Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
grp-almf
feedback-fly-embryo-crocker
Commits
7cba4d6a
Commit
7cba4d6a
authored
Feb 26, 2020
by
Aliaksandr Halavatyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove obsolete auto selection job
parent
3213af56
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
344 deletions
+0
-344
src/main/java/feedback/fly/embryo/jobs/Job_SelectMultipleEmbryosAuto.java
...edback/fly/embryo/jobs/Job_SelectMultipleEmbryosAuto.java
+0
-344
No files found.
src/main/java/feedback/fly/embryo/jobs/Job_SelectMultipleEmbryosAuto.java
deleted
100644 → 0
View file @
3213af56
package
feedback.fly.embryo.jobs
;
import
java.awt.Color
;
import
java.awt.geom.Point2D
;
import
java.io.File
;
import
java.util.concurrent.TimeUnit
;
import
automic.online.microscope.ZeissKeys
;
import
automic.online.jobs.Job_Default
;
import
automic.parameters.ParameterCollection
;
import
automic.parameters.ParameterType
;
import
automic.utils.ArrIndUtils
;
import
automic.utils.DebugVisualiserSettings
;
import
automic.utils.roi.ParticleFilterer
;
import
automic.utils.roi.ROIManipulator2D
;
import
ij.IJ
;
import
ij.ImageJ
;
import
ij.ImagePlus
;
import
ij.gui.Overlay
;
import
ij.gui.Roi
;
import
ij.plugin.Duplicator
;
import
ij.plugin.filter.MaximumFinder
;
import
ij.plugin.filter.ParticleAnalyzer
;
import
ij.plugin.filter.RankFilters
;
import
ij.plugin.frame.RoiManager
;
import
ij.process.ImageProcessor
;
import
loci.plugins.BF
;
import
loci.plugins.in.ImporterOptions
;
public
class
Job_SelectMultipleEmbryosAuto
extends
Job_Default
{
public
static
final
String
KEY_WELL_CHANNEL_INDEX
=
"LZ well (brightfield) channel index"
;
public
static
final
String
KEY_WELL_CHANNEL_THRESHOLD
=
"LZ well (brightfield) channel threshold"
;
public
static
final
String
KEY_EMBRYO_CHANNEL_INDEX
=
"LZ embryo (fluorescence) channel index"
;
public
static
final
String
KEY_EMBRYO_CHANNEL_FILTER_RADIUS
=
"LZ embryo (fluorescence) channel filter radius"
;
public
static
final
String
KEY_EMBRYO_CHANNEL_THRESHOLD
=
"LZ embryo (fluorescence) channel threshold"
;
public
static
final
String
KEY_WATERSHED_TOLERANCE
=
"Watershed tolerance"
;
public
static
final
String
KEY_EMBRYO_MIN_SIZE
=
"Embryo minimal size (pixels)"
;
public
static
final
String
KEY_EMBRYO_MAX_SIZE
=
"Embryo maximal size (pixels)"
;
public
static
final
String
KEY_EMBRYO_MIN_INTENSITY
=
"Embryo minimal intensity"
;
public
static
final
String
KEY_EMBRYO_MAX_INTENSITY
=
"Embryo maximal intensity"
;
public
static
final
String
KEY_EMBRYO_MIN_AR
=
"Embryo minimal aspect ratio"
;
public
static
final
String
KEY_EMBRYO_MAX_AR
=
"Embryo maximal aspect ratio"
;
public
static
final
String
KEY_EMBRYO_MAX_COUNT
=
"Maximal number of embryos from well"
;
public
static
final
String
KEY_WAIT_IMAGE_OPENING
=
"Wait for image opening (milliseconds)"
;
//private static final Roi nullRoi=null;
protected
ImagePlus
img
=
null
;
//private Roi selectedPointsRoi;
//private Integer selectedXPosition;
//private Integer selectedYPosition;
private
Point2D
.
Double
[]
selectedPoints
;
private
Roi
wellRoi
;
private
Roi
[]
embryoRois
;
private
Roi
[]
selectedEmbryoRois
;
//private boolean selectionMade=false;
//private boolean invert_Z;
private
int
wellBrightFieldChannel
=
2
;
private
int
wellBrightFieldThreshold
=
10
;
private
int
embryoFluorChannel
=
1
;
private
double
embryoFluorFilterRadius
=
5.0
;
private
int
embryoFluorThreshold
=
70
;
private
double
watershedTolerance
=
100.0
;
private
int
embryoMinSize
=
500
;
private
int
embryoMaxSize
=
10000
;
private
double
embryoMinIntensity
=
50.0
;
private
double
embryoMaxIntensity
=
256.0
;
private
double
embryoMinAR
=
1.8
;
private
double
embryoMaxAR
=
10.0
;
private
int
embryoMaxCount
=
5
;
private
int
imageOpeningTimeDelay
=
3000
;
//private int initialLocationY;
@Override
protected
void
cleanIterOutput
(){
img
=
null
;
selectedPoints
=
null
;
wellRoi
=
null
;
embryoRois
=
null
;
selectedEmbryoRois
=
null
;
}
@Override
protected
void
preProcessOnline
()
throws
Exception
{
currentTable
.
setFileAbsolutePath
(
newImgFile
,
curDInd
,
imgColumnNm
,
"IMG"
);
String
Exper_nm
=
newImgFile
.
getName
();
Exper_nm
=
Exper_nm
.
substring
(
0
,
Exper_nm
.
indexOf
(
fileTag
));
this
.
setSharedValue
(
"Experiment Name"
,
Exper_nm
);
TimeUnit
.
MILLISECONDS
.
sleep
(
imageOpeningTimeDelay
);
//img=ImageOpenerWithBioformats.openImage(newImgFile);
img
=
openSelectedSlices
(
newImgFile
);
}
@Override
protected
void
preProcessOffline
()
throws
Exception
{
//img=ImageOpenerWithBioformats.openImage(currentTable.getFile(curDInd, imgColumnNm, "IMG"));
img
=
openSelectedSlices
(
newImgFile
);
}
protected
ImagePlus
openSelectedSlices
(
File
_imageFile
)
throws
Exception
{
ImporterOptions
options
=
new
ImporterOptions
();
options
.
setAutoscale
(
true
);
options
.
setId
(
_imageFile
.
getAbsolutePath
());
return
BF
.
openImagePlus
(
options
)[
0
];
}
@Override
protected
boolean
runProcessing
()
throws
Exception
{
this
.
showDebug
(
img
,
"original image"
,
true
);
wellRoi
=
getWellRoi
(
new
Duplicator
().
run
(
img
,
wellBrightFieldChannel
,
wellBrightFieldChannel
,
1
,
1
,
1
,
1
));
if
(
wellRoi
==
null
)
return
false
;
identifyEmbryos
(
new
Duplicator
().
run
(
img
,
embryoFluorChannel
,
embryoFluorChannel
,
1
,
1
,
1
,
1
));
if
(
embryoRois
==
null
)
return
false
;
if
(
embryoRois
.
length
<
1
)
return
false
;
if
(
embryoRois
.
length
<=
embryoMaxCount
){
selectedEmbryoRois
=
embryoRois
;
}
else
{
int
[]
selectedIndexes
=
ArrIndUtils
.
getRandomIndexes
(
embryoRois
.
length
,
embryoMaxCount
);
selectedEmbryoRois
=
new
Roi
[
embryoMaxCount
];
for
(
int
i
=
0
;
i
<
embryoMaxCount
;
i
++)
selectedEmbryoRois
[
i
]=
embryoRois
[
selectedIndexes
[
i
]];
}
for
(
Roi
r:
selectedEmbryoRois
)
r
.
setStrokeColor
(
Color
.
cyan
);
double
x
,
y
;
selectedPoints
=
new
Point2D
.
Double
[
selectedEmbryoRois
.
length
];
for
(
int
i
=
0
;
i
<
selectedEmbryoRois
.
length
;
i
++){
x
=
selectedEmbryoRois
[
i
].
getContourCentroid
()[
0
];
y
=
selectedEmbryoRois
[
i
].
getContourCentroid
()[
1
];
selectedPoints
[
i
]=
new
Point2D
.
Double
(
x
,
y
);
}
return
true
;
}
private
Roi
getWellRoi
(
ImagePlus
_2dimage
)
throws
Exception
{
IJ
.
setThreshold
(
_2dimage
,
wellBrightFieldThreshold
,
Double
.
MAX_VALUE
);
RoiManager
rm
=
ROIManipulator2D
.
getEmptyRm
();
ParticleAnalyzer
pAnalyzer
=
new
ParticleAnalyzer
(
ParticleAnalyzer
.
ADD_TO_MANAGER
|
ParticleAnalyzer
.
SHOW_NONE
|
ParticleAnalyzer
.
FOUR_CONNECTED
,
0
,
null
,
_2dimage
.
getWidth
()*
_2dimage
.
getHeight
()/
5
,
Double
.
MAX_VALUE
,
0.0
,
1.0
);
pAnalyzer
.
analyze
(
_2dimage
);
if
(
rm
.
getCount
()<
1
)
return
null
;
Roi
[]
segmentedRegions
=
rm
.
getRoisAsArray
();
Roi
identifiedWellRoi
=
ROIManipulator2D
.
selBiggestRoi
(
_2dimage
,
segmentedRegions
);
identifiedWellRoi
.
setStrokeColor
(
Color
.
MAGENTA
);
this
.
showDebug
(
_2dimage
,
"Well segmentation"
,
false
,
new
Overlay
(
identifiedWellRoi
));
return
identifiedWellRoi
;
}
private
void
identifyEmbryos
(
ImagePlus
_embryoImage
)
throws
Exception
{
new
RankFilters
().
rank
(
_embryoImage
.
getProcessor
(),
embryoFluorFilterRadius
,
RankFilters
.
MEDIAN
);
this
.
showDebug
(
_embryoImage
,
"Image for embryo segmentation"
,
true
);
ImageProcessor
maskProcessor
=
new
MaximumFinder
().
findMaxima
(
_embryoImage
.
getProcessor
(),
watershedTolerance
,
embryoFluorThreshold
,
MaximumFinder
.
SEGMENTED
,
false
,
false
);
ImagePlus
watershedMaskImage
=
new
ImagePlus
(
"Embryo Mask Image"
,
maskProcessor
);
this
.
showDebug
(
watershedMaskImage
,
"Watershed mask"
,
true
);
IJ
.
setThreshold
(
watershedMaskImage
,
125
,
255
);
RoiManager
rm
=
ROIManipulator2D
.
getEmptyRm
();
ParticleAnalyzer
pAnalyzer
=
new
ParticleAnalyzer
(
ParticleAnalyzer
.
ADD_TO_MANAGER
|
ParticleAnalyzer
.
SHOW_NONE
|
ParticleAnalyzer
.
FOUR_CONNECTED
|
ParticleAnalyzer
.
EXCLUDE_EDGE_PARTICLES
,
0
,
null
,
embryoMinSize
,
embryoMaxSize
,
0.0
,
1.0
);
pAnalyzer
.
analyze
(
watershedMaskImage
);
if
(
rm
.
getCount
()<
1
)
return
;
Roi
[]
identifiedRois
=
rm
.
getRoisAsArray
();
ParticleFilterer
embryoFilter
=
new
ParticleFilterer
(
_embryoImage
.
getProcessor
(),
identifiedRois
);
embryoFilter
.
filterInRoi
(
wellRoi
);
embryoFilter
.
filterThr
(
ParticleFilterer
.
MEAN
,
embryoMinIntensity
,
embryoMaxIntensity
);
embryoFilter
.
filterThr
(
ParticleFilterer
.
ASPECT_RATIO
,
embryoMinAR
,
embryoMaxAR
);
embryoRois
=
embryoFilter
.
getPassedRois
();
if
(
embryoRois
==
null
)
return
;
for
(
Roi
r:
embryoRois
)
r
.
setStrokeColor
(
Color
.
yellow
);
this
.
showDebug
(
_embryoImage
,
"Segmented embryos"
,
true
,
this
.
createOverlay
());
return
;
}
@Override
protected
Overlay
createOverlay
(){
Overlay
o
=
new
Overlay
();
if
(
wellRoi
!=
null
)
o
.
add
(
wellRoi
);
if
(
embryoRois
!=
null
)
for
(
Roi
r:
embryoRois
){
o
.
add
(
r
);
}
return
o
;
}
@Override
public
void
visualise
(
int
_xvis
,
int
_yvis
){
img
.
setDisplayMode
(
IJ
.
COMPOSITE
);
this
.
visualiseImg
(
img
,
getOverlay
(),
_xvis
,
_yvis
);
img
.
setC
(
embryoFluorChannel
);
}
@Override
public
void
postProcessSuccess
()
throws
Exception
{
//PointRoi saveRoi=null;
//form comma-separated strings with coordinates
String
xstr
=
""
,
ystr
=
""
,
zstr
=
""
;
// submit 3d points in future
for
(
int
i
=
0
;
i
<
selectedEmbryoRois
.
length
;
i
++){
if
(
i
>
0
){
xstr
+=
";"
;
ystr
+=
";"
;
zstr
+=
";"
;
}
xstr
+=
selectedPoints
[
i
].
x
;
ystr
+=
selectedPoints
[
i
].
y
;
zstr
+=
"0"
;
}
ZeissKeys
.
submitCommandsToMicroscope
(
"trigger1"
,
xstr
,
ystr
,
zstr
,
""
,
""
,
""
,
""
,
""
);
saveRoisForImage
(
newImgFile
,
getOverlay
().
toArray
());
//saveRoiForImage(newImgFile,saveRoi);
this
.
setSharedValue
(
"Zoom Points"
,
selectedPoints
);
this
.
setSharedValue
(
"Zoom Counter"
,
-
1
);
this
.
setSharedValue
(
"Selected Embryo Rois"
,
selectedEmbryoRois
);
}
@Override
public
ParameterCollection
createJobParameters
(){
ParameterCollection
jobCollection
=
new
ParameterCollection
();
jobCollection
.
addParameter
(
KEY_WELL_CHANNEL_INDEX
,
null
,
wellBrightFieldChannel
,
ParameterType
.
INT_PARAMETER
);
jobCollection
.
addParameter
(
KEY_WELL_CHANNEL_THRESHOLD
,
null
,
wellBrightFieldThreshold
,
ParameterType
.
INT_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_CHANNEL_INDEX
,
null
,
embryoFluorChannel
,
ParameterType
.
INT_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_CHANNEL_FILTER_RADIUS
,
null
,
embryoFluorFilterRadius
,
ParameterType
.
DOUBLE_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_CHANNEL_THRESHOLD
,
null
,
embryoFluorThreshold
,
ParameterType
.
INT_PARAMETER
);
jobCollection
.
addParameter
(
KEY_WATERSHED_TOLERANCE
,
null
,
watershedTolerance
,
ParameterType
.
DOUBLE_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_MIN_SIZE
,
null
,
embryoMinSize
,
ParameterType
.
INT_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_MAX_SIZE
,
null
,
embryoMaxSize
,
ParameterType
.
INT_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_MIN_INTENSITY
,
null
,
embryoMinIntensity
,
ParameterType
.
DOUBLE_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_MAX_INTENSITY
,
null
,
embryoMaxIntensity
,
ParameterType
.
DOUBLE_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_MIN_AR
,
null
,
embryoMinAR
,
ParameterType
.
DOUBLE_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_MAX_AR
,
null
,
embryoMaxAR
,
ParameterType
.
DOUBLE_PARAMETER
);
jobCollection
.
addParameter
(
KEY_EMBRYO_MAX_COUNT
,
null
,
5
,
ParameterType
.
INT_PARAMETER
);
jobCollection
.
addParameter
(
KEY_WAIT_IMAGE_OPENING
,
null
,
imageOpeningTimeDelay
,
ParameterType
.
INT_PARAMETER
);
return
jobCollection
;
}
@Override
public
void
parseInputParameterValues
(
ParameterCollection
_jobParameterCollection
){
this
.
wellBrightFieldChannel
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_WELL_CHANNEL_INDEX
);
this
.
wellBrightFieldThreshold
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_WELL_CHANNEL_THRESHOLD
);
this
.
embryoFluorChannel
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_CHANNEL_INDEX
);
this
.
embryoFluorFilterRadius
=(
Double
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_CHANNEL_FILTER_RADIUS
);
this
.
embryoFluorThreshold
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_CHANNEL_THRESHOLD
);
this
.
watershedTolerance
=(
Double
)
_jobParameterCollection
.
getParameterValue
(
KEY_WATERSHED_TOLERANCE
);
this
.
embryoMinSize
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_MIN_SIZE
);
this
.
embryoMaxSize
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_MAX_SIZE
);
this
.
embryoMinIntensity
=(
Double
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_MIN_INTENSITY
);
this
.
embryoMaxIntensity
=(
Double
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_MAX_INTENSITY
);
this
.
embryoMinAR
=(
Double
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_MIN_AR
);
this
.
embryoMaxAR
=(
Double
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_MAX_AR
);
this
.
embryoMaxCount
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_EMBRYO_MAX_COUNT
);
this
.
imageOpeningTimeDelay
=(
Integer
)
_jobParameterCollection
.
getParameterValue
(
KEY_WAIT_IMAGE_OPENING
);
}
@Override
protected
DebugVisualiserSettings
getDebugVisualiserSettings
(){
return
new
DebugVisualiserSettings
(-
1
,
10
,
10
,
2
);
}
/**
* offline debugging
* @param args unsused
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// start ImageJ
new
ImageJ
();
String
tblPth
=
"X:\\group\\ALMFstuff\\Aliaksandr\\User_data\\Crocker-fly-feedback\\03082019_march_test"
;
String
tblFnm
=
"summary_test03_.txt"
;
Job_SelectMultipleEmbryosAuto
testJob
=
new
Job_SelectMultipleEmbryosAuto
();
testJob
.
initialise
(
null
,
"LZ.Image"
,
false
);
testJob
.
testJobMicTable
(
0
,
tblPth
,
tblFnm
);
}
}
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