Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
imagej-elphel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Elphel
imagej-elphel
Commits
9898d7a6
Commit
9898d7a6
authored
Dec 25, 2016
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more experimenting
parent
2034f62d
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
853 additions
and
145 deletions
+853
-145
EyesisCorrectionParameters.java
src/main/java/EyesisCorrectionParameters.java
+40
-22
Eyesis_Correction.java
src/main/java/Eyesis_Correction.java
+119
-5
FactorConvKernel.java
src/main/java/FactorConvKernel.java
+694
-118
No files found.
src/main/java/EyesisCorrectionParameters.java
View file @
9898d7a6
...
...
@@ -1650,20 +1650,25 @@ public class EyesisCorrectionParameters {
public
static
class
DCTParameters
{
public
int
dct_size
=
32
;
//
public
int
asym_size
=
6
;
//
public
int
asym_pixels
=
10
;
// maximal number of non-zero pixels in direct convolution kernel
public
int
asym_distance
=
2
;
// how far to try a new asym kernel pixel from existing ones
public
int
dct_window
=
1
;
// currently only 3 types of windows - 0 (none), 1 and 2
public
int
LMA_steps
=
100
;
public
double
fact_precision
=
0.003
;
// stop iterations if error rms less than this part of target kernel rms
public
double
compactness
=
1.0
;
public
int
asym_tax_free
=
1
;
// "compactness" does not apply to pixels with |x|<=asym_tax_free and |y| <= asym_tax_free
public
int
asym_tax_free
=
5
;
// "compactness" does not apply to pixels with |x|<=asym_tax_free and |y| <= asym_tax_free
public
double
dbg_x
=
0
;
public
double
dbg_y
=
0
;
public
double
dbg_x1
=
0
;
public
double
dbg_y1
=
0
;
public
double
dbg_sigma
=
2.0
;
public
String
dbg_mask
=
".........:::::::::.........:::::::::......*..:::::*:::.........:::::::::........."
;
public
DCTParameters
(
int
dct_size
,
int
asym_size
,
int
dct_window
,
double
compactness
,
int
asym_tax_free
)
{
public
DCTParameters
(
int
dct_size
,
int
asym_size
,
int
asym_pixels
,
int
asym_distance
,
int
dct_window
,
double
compactness
,
int
asym_tax_free
)
{
this
.
dct_size
=
dct_size
;
this
.
asym_size
=
asym_size
;
this
.
asym_pixels
=
asym_pixels
;
this
.
asym_distance
=
asym_distance
;
this
.
dct_window
=
dct_window
;
this
.
compactness
=
compactness
;
this
.
asym_tax_free
=
asym_tax_free
;
...
...
@@ -1671,36 +1676,44 @@ public class EyesisCorrectionParameters {
public
void
setProperties
(
String
prefix
,
Properties
properties
){
properties
.
setProperty
(
prefix
+
"dct_size"
,
this
.
dct_size
+
""
);
properties
.
setProperty
(
prefix
+
"asym_size"
,
this
.
asym_size
+
""
);
properties
.
setProperty
(
prefix
+
"asym_pixels"
,
this
.
asym_pixels
+
""
);
properties
.
setProperty
(
prefix
+
"asym_distance"
,
this
.
asym_distance
+
""
);
properties
.
setProperty
(
prefix
+
"dct_window"
,
this
.
dct_window
+
""
);
properties
.
setProperty
(
prefix
+
"compactness"
,
this
.
compactness
+
""
);
properties
.
setProperty
(
prefix
+
"fact_precision"
,
this
.
fact_precision
+
""
);
properties
.
setProperty
(
prefix
+
"asym_tax_free"
,
this
.
asym_tax_free
+
""
);
properties
.
setProperty
(
prefix
+
"LMA_steps"
,
this
.
LMA_steps
+
""
);
properties
.
setProperty
(
prefix
+
"dbg_x"
,
this
.
dbg_x
+
""
);
properties
.
setProperty
(
prefix
+
"dbg_y"
,
this
.
dbg_y
+
""
);
properties
.
setProperty
(
prefix
+
"dbg_x1"
,
this
.
dbg_x1
+
""
);
properties
.
setProperty
(
prefix
+
"dbg_y1"
,
this
.
dbg_y1
+
""
);
properties
.
setProperty
(
prefix
+
"dbg_sigma"
,
this
.
dbg_sigma
+
""
);
properties
.
setProperty
(
prefix
+
"dbg_mask"
,
this
.
dbg_mask
+
""
);
}
public
void
getProperties
(
String
prefix
,
Properties
properties
){
if
(
properties
.
getProperty
(
prefix
+
"dct_size"
)!=
null
)
this
.
dct_size
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"dct_size"
));
if
(
properties
.
getProperty
(
prefix
+
"asym_size"
)!=
null
)
this
.
asym_size
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"asym_size"
));
if
(
properties
.
getProperty
(
prefix
+
"asym_pixels"
)!=
null
)
this
.
asym_pixels
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"asym_pixels"
));
if
(
properties
.
getProperty
(
prefix
+
"asym_distance"
)!=
null
)
this
.
asym_distance
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"asym_distance"
));
if
(
properties
.
getProperty
(
prefix
+
"dct_window"
)!=
null
)
this
.
dct_window
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"dct_window"
));
if
(
properties
.
getProperty
(
prefix
+
"compactness"
)!=
null
)
this
.
compactness
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"compactness"
));
if
(
properties
.
getProperty
(
prefix
+
"fact_precision"
)!=
null
)
this
.
fact_precision
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"fact_precision"
));
if
(
properties
.
getProperty
(
prefix
+
"asym_tax_free"
)!=
null
)
this
.
asym_tax_free
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"asym_tax_free"
));
if
(
properties
.
getProperty
(
prefix
+
"LMA_steps"
)!=
null
)
this
.
LMA_steps
=
Integer
.
parseInt
(
properties
.
getProperty
(
prefix
+
"LMA_steps"
));
if
(
properties
.
getProperty
(
prefix
+
"dbg_x"
)!=
null
)
this
.
dbg_x
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"dbg_x"
));
if
(
properties
.
getProperty
(
prefix
+
"dbg_y"
)!=
null
)
this
.
dbg_y
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"dbg_y"
));
if
(
properties
.
getProperty
(
prefix
+
"dbg_x1"
)!=
null
)
this
.
dbg_x1
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"dbg_x1"
));
if
(
properties
.
getProperty
(
prefix
+
"dbg_y1"
)!=
null
)
this
.
dbg_y1
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"dbg_y1"
));
if
(
properties
.
getProperty
(
prefix
+
"dbg_sigma"
)!=
null
)
this
.
dbg_sigma
=
Double
.
parseDouble
(
properties
.
getProperty
(
prefix
+
"dbg_sigma"
));
if
(
properties
.
getProperty
(
prefix
+
"dbg_mask"
)!=
null
)
this
.
dbg_mask
=
properties
.
getProperty
(
prefix
+
"dbg_mask"
);
}
public
boolean
showDialog
()
{
GenericDialog
gd
=
new
GenericDialog
(
"Set DCT parameters"
);
gd
.
addNumericField
(
"DCT size"
,
this
.
dct_size
,
0
);
//32
gd
.
addNumericField
(
"Size of asymmetrical (non-DCT) kernel"
,
this
.
asym_size
,
0
);
//6
gd
.
addNumericField
(
"Maximal number of non-zero pixels in direct convolution kernel"
,
this
.
asym_pixels
,
0
);
//6
gd
.
addNumericField
(
"How far to try a new asym kernel pixel from existing ones"
,
this
.
asym_distance
,
0
);
//6
gd
.
addNumericField
(
"MDCT window type (0,1,2)"
,
this
.
dct_window
,
0
);
//0..2
gd
.
addNumericField
(
"LMA_steps"
,
this
.
LMA_steps
,
0
);
//0..2
gd
.
addNumericField
(
"Compactness (punish off-center asym_kernel pixels (proportional to r^2)"
,
this
.
compactness
,
2
);
//0..2
...
...
@@ -1712,11 +1725,14 @@ public class EyesisCorrectionParameters {
gd
.
addNumericField
(
"dbg_x1"
,
this
.
dbg_x1
,
2
);
//0..2
gd
.
addNumericField
(
"dbg_y1"
,
this
.
dbg_y1
,
2
);
//0..2
gd
.
addNumericField
(
"dbg_sigma"
,
this
.
dbg_sigma
,
3
);
//0..2
gd
.
addStringField
(
"Debug mask (anything but * is false)"
,
this
.
dbg_mask
,
100
);
// gd.addNumericField("Debug Level:", MASTER_DEBUG_LEVEL, 0);
gd
.
showDialog
();
if
(
gd
.
wasCanceled
())
return
false
;
this
.
dct_size
=
(
int
)
gd
.
getNextNumber
();
this
.
asym_size
=
(
int
)
gd
.
getNextNumber
();
this
.
asym_pixels
=
(
int
)
gd
.
getNextNumber
();
this
.
asym_distance
=
(
int
)
gd
.
getNextNumber
();
this
.
dct_window
=
(
int
)
gd
.
getNextNumber
();
this
.
LMA_steps
=
(
int
)
gd
.
getNextNumber
();
this
.
compactness
=
gd
.
getNextNumber
();
...
...
@@ -1727,6 +1743,8 @@ public class EyesisCorrectionParameters {
this
.
dbg_x1
=
gd
.
getNextNumber
();
this
.
dbg_y1
=
gd
.
getNextNumber
();
this
.
dbg_sigma
=
gd
.
getNextNumber
();
this
.
dbg_mask
=
gd
.
getNextString
();
// MASTER_DEBUG_LEVEL= (int) gd.getNextNumber();
return
true
;
}
...
...
src/main/java/Eyesis_Correction.java
View file @
9898d7a6
...
...
@@ -87,9 +87,11 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
public
static
EyesisCorrectionParameters
.
DCTParameters
DCT_PARAMETERS
=
new
EyesisCorrectionParameters
.
DCTParameters
(
32
,
// dct_size
6
,
// asym_size
10
,
// asym_pixels = 10; // maximal number of non-zero pixels in direct convolution kernel
2
,
// asym_distance = 2; // how far to try a new asym kernel pixel from existing ones
1
,
// dct_window
1.0
,
// double compactness
1
// asym_tax_free);
1.0
,
// double compactness
5
// asym_tax_free);
);
public
static
EyesisDCT
EYESIS_DCT
=
null
;
...
...
@@ -452,6 +454,7 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
addButton
(
"DCT test 3"
,
panelDct1
,
color_process
);
addButton
(
"DCT test 4"
,
panelDct1
,
color_process
);
addButton
(
"Test Kernel Factorization"
,
panelDct1
,
color_process
);
addButton
(
"Min Kernel Factorization"
,
panelDct1
,
color_process
);
addButton
(
"Create DCT kernels"
,
panelDct1
,
color_process
);
add
(
panelDct1
);
}
...
...
@@ -2874,11 +2877,31 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
}
}
boolean
[]
mask
=
null
;
if
(!
DCT_PARAMETERS
.
dbg_mask
.
equals
(
""
)){
mask
=
new
boolean
[
DCT_PARAMETERS
.
asym_size
*
DCT_PARAMETERS
.
asym_size
];
for
(
int
ii
=
0
;
ii
<
mask
.
length
;
ii
++)
{
mask
[
ii
]
=
((
ii
<=
DCT_PARAMETERS
.
dbg_mask
.
length
())
&&
(
DCT_PARAMETERS
.
dbg_mask
.
charAt
(
ii
)
==
'*'
));
}
/*
System.out.println("asym mask: ");
for (int ii=0;ii<DCT_PARAMETERS.asym_size;ii++){
System.out.print(ii+": ");
for (int jj=0;jj<DCT_PARAMETERS.asym_size;jj++){
System.out.print((mask[ii*DCT_PARAMETERS.asym_size+jj]?" X":" .")+" ");
}
System.out.println();
}
*/
}
boolean
result
=
factorConvKernel
.
calcKernels
(
target_expanded
,
DCT_PARAMETERS
.
asym_size
,
DCT_PARAMETERS
.
dct_size
,
DCT_PARAMETERS
.
fact_precision
);
DCT_PARAMETERS
.
fact_precision
,
mask
);
System
.
out
.
println
(
"factorConvKernel.calcKernels() returned: >>> "
+
result
+
" <<<"
);
double
[]
sym_kernel
=
factorConvKernel
.
getSymKernel
();
double
[]
asym_kernel
=
factorConvKernel
.
getAsymKernel
();
...
...
@@ -2893,8 +2916,99 @@ private Panel panel1,panel2,panel3,panel4,panel5,panel5a, panel6,panel7,panelPos
SDFA_INSTANCE
.
showArrays
(
compare_kernels
,
target_expanded_size
,
target_expanded_size
,
true
,
"compare_kernels"
);
// SDFA_INSTANCE.showArrays(convolved, target_kernel_size, target_kernel_size, "convolved");
return
;
}
else
if
(
label
.
equals
(
"Min Kernel Factorization"
)){
DEBUG_LEVEL
=
MASTER_DEBUG_LEVEL
;
if
(!
DCT_PARAMETERS
.
showDialog
())
return
;
FactorConvKernel
factorConvKernel
=
new
FactorConvKernel
();
factorConvKernel
.
setDebugLevel
(
DEBUG_LEVEL
);
factorConvKernel
.
numIterations
=
DCT_PARAMETERS
.
LMA_steps
;
factorConvKernel
.
setAsymCompactness
(
DCT_PARAMETERS
.
compactness
,
DCT_PARAMETERS
.
asym_tax_free
);
int
target_kernel_size
=
2
*
DCT_PARAMETERS
.
dct_size
-
1
;
double
[]
target_kernel
=
new
double
[
target_kernel_size
*
target_kernel_size
];
for
(
int
ii
=
0
;
ii
<
target_kernel
.
length
;
ii
++)
target_kernel
[
ii
]=
0.0
;
double
dist
=
Math
.
sqrt
((
DCT_PARAMETERS
.
dbg_x1
-
DCT_PARAMETERS
.
dbg_x
)*(
DCT_PARAMETERS
.
dbg_x1
-
DCT_PARAMETERS
.
dbg_x
)+
(
DCT_PARAMETERS
.
dbg_y1
-
DCT_PARAMETERS
.
dbg_y
)*(
DCT_PARAMETERS
.
dbg_y1
-
DCT_PARAMETERS
.
dbg_y
));
int
num_steps
=
(
int
)
Math
.
round
(
dist
+
0.5
);
dist
=
num_steps
;
for
(
int
ii
=
0
;
ii
<=
num_steps
;
ii
++)
{
int
dbg_x
=
(
int
)
Math
.
round
((
DCT_PARAMETERS
.
dbg_x1
-
DCT_PARAMETERS
.
dbg_x
)*
ii
/
dist
+
DCT_PARAMETERS
.
dbg_x
);
int
dbg_y
=
(
int
)
Math
.
round
((
DCT_PARAMETERS
.
dbg_y1
-
DCT_PARAMETERS
.
dbg_y
)*
ii
/
dist
+
DCT_PARAMETERS
.
dbg_y
);
target_kernel
[(
target_kernel_size
/
2
+
dbg_y
)*
target_kernel_size
+(
target_kernel_size
/
2
+
dbg_x
)]
=
1.0
;
if
(
MASTER_DEBUG_LEVEL
>
2
)
{
System
.
out
.
println
(
ii
+
": "
+((
DCT_PARAMETERS
.
dbg_x1
-
DCT_PARAMETERS
.
dbg_x
)*
ii
/
dist
+
DCT_PARAMETERS
.
dbg_x
)+
" / "
+
((
DCT_PARAMETERS
.
dbg_y1
-
DCT_PARAMETERS
.
dbg_y
)*
ii
/
dist
+
DCT_PARAMETERS
.
dbg_y
)+
" ("
+
dbg_x
+
":"
+
dbg_y
+
")"
);
}
}
double
blurSigma
=
DCT_PARAMETERS
.
dbg_sigma
;
DoubleGaussianBlur
gb
=
null
;
if
(
blurSigma
>
0
)
gb
=
new
DoubleGaussianBlur
();
if
(
blurSigma
>
0
)
gb
.
blurDouble
(
target_kernel
,
target_kernel_size
,
target_kernel_size
,
blurSigma
,
blurSigma
,
0.01
);
// SDFA_INSTANCE.showArrays(target_kernel, target_kernel_size, target_kernel_size, "target_kernel");
int
target_expanded_size
=
2
*
DCT_PARAMETERS
.
dct_size
+
DCT_PARAMETERS
.
asym_size
-
2
;
double
[]
target_expanded
=
new
double
[
target_expanded_size
*
target_expanded_size
];
for
(
int
ii
=
0
;
ii
<
target_expanded
.
length
;
ii
++)
target_expanded
[
ii
]=
0.0
;
int
left_top_margin
=
((
DCT_PARAMETERS
.
asym_size
-
1
)/
2
);
for
(
int
ii
=
0
;
ii
<
target_kernel_size
;
ii
++){
for
(
int
jj
=
0
;
jj
<
target_kernel_size
;
jj
++){
target_expanded
[(
ii
+
left_top_margin
)*
target_expanded_size
+
(
jj
+
left_top_margin
)]
=
target_kernel
[
ii
*
target_kernel_size
+
jj
];
}
}
int
numPixels
=
factorConvKernel
.
calcKernels
(
target_expanded
,
DCT_PARAMETERS
.
asym_size
,
DCT_PARAMETERS
.
dct_size
,
DCT_PARAMETERS
.
fact_precision
,
DCT_PARAMETERS
.
asym_pixels
,
DCT_PARAMETERS
.
asym_distance
);
/*
public int calcKernels(
double []target_kernel,
int asym_size,
int sym_radius,
double fact_precision,
int asym_pixels, // maximal number of non-zero pixels in asymmmetrical kernel
int asym_distance){ // how far to seed a new pixel
*/
System
.
out
.
println
(
"factorConvKernel.calcKernels() returned: >>> "
+
numPixels
+
" <<<"
);
double
[]
sym_kernel
=
factorConvKernel
.
getSymKernel
();
double
[]
asym_kernel
=
factorConvKernel
.
getAsymKernel
();
double
[]
convolved
=
factorConvKernel
.
getConvolved
();
double
[][]
compare_kernels
=
{
target_expanded
,
convolved
};
System
.
out
.
println
(
"DCT_PARAMETERS.dct_size="
+
DCT_PARAMETERS
.
dct_size
+
" DCT_PARAMETERS.asym_size="
+
DCT_PARAMETERS
.
asym_size
);
System
.
out
.
println
(
"sym_kernel.length="
+
sym_kernel
.
length
);
System
.
out
.
println
(
"asym_kernel.length="
+
asym_kernel
.
length
);
System
.
out
.
println
(
"convolved.length="
+
convolved
.
length
);
SDFA_INSTANCE
.
showArrays
(
sym_kernel
,
DCT_PARAMETERS
.
dct_size
,
DCT_PARAMETERS
.
dct_size
,
"sym_kernel"
);
SDFA_INSTANCE
.
showArrays
(
asym_kernel
,
DCT_PARAMETERS
.
asym_size
,
DCT_PARAMETERS
.
asym_size
,
"asym_kernel"
);
SDFA_INSTANCE
.
showArrays
(
compare_kernels
,
target_expanded_size
,
target_expanded_size
,
true
,
"compare_kernels"
);
// SDFA_INSTANCE.showArrays(convolved, target_kernel_size, target_kernel_size, "convolved");
return
;
}
else
if
(
label
.
equals
(
"DCT test 4"
))
{
/*
public int calcKernels(
double []target_kernel,
int asym_size,
int sym_radius,
double fact_precision,
int asym_pixels, // maximal number of non-zero pixels in asymmmetrical kernel
int asym_distance){ // how far to seed a new pixel
*/
DEBUG_LEVEL
=
MASTER_DEBUG_LEVEL
;
EYESIS_CORRECTIONS
.
setDebug
(
DEBUG_LEVEL
);
String
configPath
=
null
;
...
...
src/main/java/FactorConvKernel.java
View file @
9898d7a6
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment