Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Spot Detector Block
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bioimage Analysis
Spot Detector Block
Commits
9bf9ed92
Commit
9bf9ed92
authored
3 years ago
by
Stéphane DALLONGEVILLE
Browse files
Options
Downloads
Patches
Plain Diff
updated for interruptible tasks (Icy 2.4.0)
parent
646ec37a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/fab/waveletspotdetectorblock/WaveletSpotDetectorBlock.java
+243
-241
243 additions, 241 deletions
...ab/waveletspotdetectorblock/WaveletSpotDetectorBlock.java
with
243 additions
and
241 deletions
src/plugins/fab/waveletspotdetectorblock/WaveletSpotDetectorBlock.java
+
243
−
241
View file @
9bf9ed92
package
plugins.fab.waveletspotdetectorblock
;
package
plugins.fab.waveletspotdetectorblock
;
import
java.util.ArrayList
;
import
icy.plugin.abstract_.Plugin
;
import
icy.plugin.abstract_.Plugin
;
import
icy.roi.ROI
;
import
icy.roi.ROI
;
import
icy.roi.ROI2D
;
import
icy.roi.ROI2D
;
import
icy.sequence.Sequence
;
import
icy.sequence.Sequence
;
import
icy.sequence.SequenceUtil
;
import
icy.system.thread.ThreadUtil
;
import
icy.system.thread.ThreadUtil
;
import
java.awt.geom.Point2D
;
import
java.util.ArrayList
;
import
javax.xml.bind.JAXBContext
;
import
plugins.adufour.blocks.lang.Block
;
import
plugins.adufour.blocks.lang.Block
;
import
plugins.adufour.blocks.util.VarList
;
import
plugins.adufour.blocks.util.VarList
;
import
plugins.adufour.vars.lang.VarBoolean
;
import
plugins.adufour.vars.lang.VarBoolean
;
import
plugins.adufour.vars.lang.VarEnum
;
import
plugins.adufour.vars.lang.VarEnum
;
import
plugins.adufour.vars.lang.VarGenericArray
;
import
plugins.adufour.vars.lang.VarInteger
;
import
plugins.adufour.vars.lang.VarInteger
;
import
plugins.adufour.vars.lang.VarROIArray
;
import
plugins.adufour.vars.lang.VarROIArray
;
import
plugins.adufour.vars.lang.VarSequence
;
import
plugins.adufour.vars.lang.VarSequence
;
...
@@ -25,248 +21,254 @@ import plugins.fab.spotDetector.detector.DetectionToROI;
...
@@ -25,248 +21,254 @@ import plugins.fab.spotDetector.detector.DetectionToROI;
import
plugins.fab.spotDetector.detector.UDWTScale
;
import
plugins.fab.spotDetector.detector.UDWTScale
;
import
plugins.fab.spotDetector.detector.UDWTWaveletCore
;
import
plugins.fab.spotDetector.detector.UDWTWaveletCore
;
public
class
WaveletSpotDetectorBlock
extends
Plugin
implements
Block
{
public
class
WaveletSpotDetectorBlock
extends
Plugin
implements
Block
{
enum
detectionMethodEnum
{
BRIGHT_SPOT
,
DARK_SPOT
}
VarSequence
inputSequenceVar
=
new
VarSequence
(
"input Sequence"
,
null
);
VarEnum
<
detectionMethodEnum
>
detectionMethod
=
new
VarEnum
<
detectionMethodEnum
>(
"Spot to detect"
,
detectionMethodEnum
.
BRIGHT_SPOT
);
VarBoolean
computeWATConsideringROIBoolean
=
new
VarBoolean
(
"Compute WAT considering ROI"
,
false
);
VarSequence
inputSequenceROIVar
=
new
VarSequence
(
"ROIs from sequence for WAT"
,
null
);
VarBoolean
force2DWaveletVar
=
new
VarBoolean
(
"Force 2D Wavelets"
,
false
);
VarROIArray
inputROIForMask
=
new
VarROIArray
(
"ROIs for detection mask"
,
null
);
VarBoolean
[]
useScaleBoolean
=
{
new
VarBoolean
(
"Scale 1"
,
false
),
new
VarBoolean
(
"Scale 2"
,
true
),
new
VarBoolean
(
"Scale 3"
,
false
),
new
VarBoolean
(
"Scale 4"
,
false
),
new
VarBoolean
(
"Scale 5"
,
false
)
};
VarInteger
[]
scaleParameter
=
{
new
VarInteger
(
"Th. scale 1:"
,
100
),
new
VarInteger
(
"Th. scale 2:"
,
100
),
new
VarInteger
(
"Th. scale 3:"
,
100
),
new
VarInteger
(
"Th. scale 4:"
,
100
),
new
VarInteger
(
"Th. scale 5:"
,
100
)
};
VarSequence
outSequence
=
new
VarSequence
(
"output Sequence"
,
null
);
VarSequence
denoisedSequence
=
new
VarSequence
(
"denoised Sequence"
,
null
);
VarSequence
binarySpotSequence
=
new
VarSequence
(
"binary Spot Sequence"
,
null
);
VarROIArray
detectionAsROIOut
=
new
VarROIArray
(
"detection as ROIs"
,
null
);
@Override
public
void
run
()
{
// test if input sequence has only 1 channel.
Sequence
inputSequence
=
inputSequenceVar
.
getValue
();
if
(
inputSequence
==
null
)
{
throw
new
VarException
(
"The input sequence must be set"
);
}
if
(
inputSequence
.
getSizeC
()
!=
1
)
{
throw
new
VarException
(
"The input sequence must contain only 1 channel. Please use 'Extract Channel' prior to the WaveletBlock"
);
}
// inputChannelVar
// init detection.
UDWTWaveletCore
waveletCore
=
new
UDWTWaveletCore
();
boolean
detectNegative
;
if
(
detectionMethod
.
getValue
()
==
detectionMethodEnum
.
BRIGHT_SPOT
)
{
detectNegative
=
false
;
}
else
{
detectNegative
=
true
;
}
boolean
computeWATwithROI
=
computeWATConsideringROIBoolean
.
getValue
();
// copy ROI from input sequence to the computation sequence
Sequence
inputComputationSequence
=
inputSequence
.
getCopy
();
if
(
inputSequenceROIVar
.
getValue
()
!=
null
)
{
for
(
ROI2D
roi
:
inputSequenceROIVar
.
getValue
().
getROI2Ds
()
)
{
ROI2D
roiCopy
=
(
ROI2D
)
roi
.
getCopy
();
if
(
roiCopy
!=
null
)
{
inputComputationSequence
.
addROI
(
roiCopy
);
}
}
}
//Icy.addSequence( inputComputationSequence );
// create UDWTScale Parameter list.
final
ArrayList
<
UDWTScale
>
UDWTScaleArrayList
=
new
ArrayList
<
UDWTScale
>();
// System.out.println("Block debug.");
ThreadUtil
.
invokeNow
(
new
Runnable
()
{
@Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
//System.out.println( "Scale enabled #" +i +" : " + useScaleBoolean[i].getValue() );
UDWTScale
scale
=
new
UDWTScale
(
i
+
1
,
useScaleBoolean
[
i
].
getValue
()
,
scaleParameter
[
i
].
getValue
()
);
UDWTScaleArrayList
.
add
(
scale
);
}
}
});
// Perform detection.
ArrayList
<
DetectionSpot
>
detectionResult
;
detectionResult
=
waveletCore
.
computeDetection
(
true
,
UDWTScaleArrayList
,
inputComputationSequence
,
detectNegative
,
computeWATwithROI
,
force2DWaveletVar
.
getValue
()
);
// System.out.println( "ROI Mask : " + inputROIForMask.getValue() );
// Filter spot with ROIs.
if
(
inputROIForMask
.
getValue
().
length
!=
0
)
{
ArrayList
<
DetectionSpot
>
detectionResultCopy
=
new
ArrayList
<
DetectionSpot
>(
detectionResult
);
detectionList:
for
(
DetectionSpot
spot
:
detectionResultCopy
)
{
// Point2D spotCoordinates = new Point2D.Double( spot.getMassCenter().x , spot.getMassCenter().y );
// spot.getMassCenter()
ROI
detectionAsROI
=
null
;
enum
detectionMethodEnum
{
BRIGHT_SPOT
,
DARK_SPOT
}
try
VarSequence
inputSequenceVar
=
new
VarSequence
(
"input Sequence"
,
null
);
{
VarEnum
<
detectionMethodEnum
>
detectionMethod
=
new
VarEnum
<
detectionMethodEnum
>(
"Spot to detect"
,
ArrayList
<
DetectionSpot
>
detectionList
=
new
ArrayList
<
DetectionSpot
>(
);
detectionMethodEnum
.
BRIGHT_SPOT
);
detectionList
.
add
(
spot
);
VarBoolean
computeWATConsideringROIBoolean
=
new
VarBoolean
(
"Compute WAT considering ROI"
,
false
);
detectionAsROI
=
DetectionToROI
.
convertDetectionToROI
(
detectionList
).
get
(
0
);
VarSequence
inputSequenceROIVar
=
new
VarSequence
(
"ROIs from sequence for WAT"
,
null
);
}
catch
(
NullPointerException
e
)
VarBoolean
force2DWaveletVar
=
new
VarBoolean
(
"Force 2D Wavelets"
,
false
);
{
VarROIArray
inputROIForMask
=
new
VarROIArray
(
"ROIs for detection mask"
,
null
);
System
.
err
.
println
(
"Error in spot to ROI conversion"
);
}
if
(
detectionAsROI
==
null
)
VarBoolean
[]
useScaleBoolean
=
{
new
VarBoolean
(
"Scale 1"
,
false
),
new
VarBoolean
(
"Scale 2"
,
true
),
{
new
VarBoolean
(
"Scale 3"
,
false
),
new
VarBoolean
(
"Scale 4"
,
false
),
new
VarBoolean
(
"Scale 5"
,
false
)};
System
.
err
.
println
(
"Can't convert spot to ROI. spot="
+
spot
);
continue
;
}
// System.out.println( "spot as ROI to test: " + detectionAsROI.getBounds5D() );
VarInteger
[]
scaleParameter
=
{
new
VarInteger
(
"Th. scale 1:"
,
100
),
new
VarInteger
(
"Th. scale 2:"
,
100
),
new
VarInteger
(
"Th. scale 3:"
,
100
),
new
VarInteger
(
"Th. scale 4:"
,
100
),
new
VarInteger
(
"Th. scale 5:"
,
100
)};
for
(
ROI
roi
:
inputROIForMask
.
getValue
()
)
VarSequence
outSequence
=
new
VarSequence
(
"output Sequence"
,
null
);
{
VarSequence
denoisedSequence
=
new
VarSequence
(
"denoised Sequence"
,
null
);
// System.out.println( "roi contenant: " + roi.getBounds5D() );
VarSequence
binarySpotSequence
=
new
VarSequence
(
"binary Spot Sequence"
,
null
);
VarROIArray
detectionAsROIOut
=
new
VarROIArray
(
"detection as ROIs"
,
null
);
if
(
roi
.
contains
(
detectionAsROI
)
)
{
// System.out.println("contains");
continue
detectionList
;
}
}
// System.out.println("don't contains");
detectionResult
.
remove
(
spot
);
@Override
public
void
run
()
{
}
// test if input sequence has only 1 channel.
}
Sequence
inputSequence
=
inputSequenceVar
.
getValue
();
if
(
inputSequence
==
null
)
{
throw
new
VarException
(
"The input sequence must be set"
);
}
// set outputs.
if
(
inputSequence
.
getSizeC
()
!=
1
)
{
// binary output: propagate ROIs.
throw
new
VarException
(
{
"The input sequence must contain only 1 channel. Please use 'Extract Channel' prior to the WaveletBlock"
);
Sequence
binarySequence
=
waveletCore
.
getBinarySequence
();
}
if
(
inputSequenceROIVar
.
getValue
()
!=
null
)
// inputChannelVar
{
for
(
ROI2D
roi
:
inputSequenceROIVar
.
getValue
().
getROI2Ds
()
)
// init detection.
{
//System.out.println("roi:"+roi);
UDWTWaveletCore
waveletCore
=
new
UDWTWaveletCore
();
String
name
=
roi
.
getName
();
boolean
detectNegative
;
ROI2D
roiCopy
=
(
ROI2D
)
roi
.
getCopy
();
roi
.
setName
(
name
);
// because of the bug when coppying roi.
if
(
detectionMethod
.
getValue
()
==
detectionMethodEnum
.
BRIGHT_SPOT
)
roiCopy
.
setName
(
name
);
// else the name has " copy" in the end of it.
{
detectNegative
=
false
;
binarySequence
.
addROI
(
roiCopy
);
}
}
else
}
{
detectNegative
=
true
;
binarySpotSequence
.
setValue
(
binarySequence
);
}
}
boolean
computeWATwithROI
=
computeWATConsideringROIBoolean
.
getValue
();
// output detection as ROI
{
// copy ROI from input sequence to the computation sequence
ArrayList
<
ROI
>
roiList
=
DetectionToROI
.
convertDetectionToROI
(
detectionResult
);
Sequence
inputComputationSequence
;
ROI
roi
[]
=
new
ROI
[
roiList
.
size
()
];
int
i
=
0
;
try
for
(
ROI
roiCandidate
:
roiList
)
{
{
inputComputationSequence
=
SequenceUtil
.
getCopy
(
inputSequence
);
roi
[
i
]
=
roiCandidate
;
}
i
++;
catch
(
InterruptedException
ex
)
}
{
detectionAsROIOut
.
setValue
(
roi
);
// interrupt process
}
return
;
}
}
if
(
inputSequenceROIVar
.
getValue
()
!=
null
)
{
@Override
for
(
ROI2D
roi
:
inputSequenceROIVar
.
getValue
().
getROI2Ds
())
public
void
declareInput
(
VarList
inputMap
)
{
{
ROI2D
roiCopy
=
(
ROI2D
)
roi
.
getCopy
();
inputMap
.
add
(
inputSequenceVar
);
inputMap
.
add
(
detectionMethod
);
if
(
roiCopy
!=
null
)
inputMap
.
add
(
"input Sequence ROIs"
,
inputSequenceROIVar
);
{
inputMap
.
add
(
computeWATConsideringROIBoolean
);
inputComputationSequence
.
addROI
(
roiCopy
);
inputMap
.
add
(
inputROIForMask
);
}
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
}
{
inputMap
.
add
(
useScaleBoolean
[
i
]
);
// Icy.addSequence( inputComputationSequence );
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
// create UDWTScale Parameter list.
{
inputMap
.
add
(
scaleParameter
[
i
]
);
final
ArrayList
<
UDWTScale
>
UDWTScaleArrayList
=
new
ArrayList
<
UDWTScale
>();
}
inputMap
.
add
(
force2DWaveletVar
);
// System.out.println("Block debug.");
}
ThreadUtil
.
invokeNow
(
new
Runnable
()
@Override
{
public
void
declareOutput
(
VarList
outputMap
)
{
@Override
// outputMap.add( outSequence );
public
void
run
()
// outputMap.add( denoisedSequence );
{
outputMap
.
add
(
binarySpotSequence
);
outputMap
.
add
(
detectionAsROIOut
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
}
// System.out.println( "Scale enabled #" +i +" : " + useScaleBoolean[i].getValue() );
UDWTScale
scale
=
new
UDWTScale
(
i
+
1
,
useScaleBoolean
[
i
].
getValue
(),
scaleParameter
[
i
].
getValue
());
UDWTScaleArrayList
.
add
(
scale
);
}
}
});
// Perform detection.
ArrayList
<
DetectionSpot
>
detectionResult
;
detectionResult
=
waveletCore
.
computeDetection
(
true
,
UDWTScaleArrayList
,
inputComputationSequence
,
detectNegative
,
computeWATwithROI
,
force2DWaveletVar
.
getValue
());
// System.out.println( "ROI Mask : " + inputROIForMask.getValue() );
// Filter spot with ROIs.
try
{
if
(
inputROIForMask
.
getValue
().
length
!=
0
)
{
ArrayList
<
DetectionSpot
>
detectionResultCopy
=
new
ArrayList
<
DetectionSpot
>(
detectionResult
);
detectionList:
for
(
DetectionSpot
spot
:
detectionResultCopy
)
{
// Point2D spotCoordinates = new Point2D.Double( spot.getMassCenter().x , spot.getMassCenter().y );
// spot.getMassCenter()
ROI
detectionAsROI
=
null
;
try
{
ArrayList
<
DetectionSpot
>
detectionList
=
new
ArrayList
<
DetectionSpot
>();
detectionList
.
add
(
spot
);
detectionAsROI
=
DetectionToROI
.
convertDetectionToROI
(
detectionList
).
get
(
0
);
}
catch
(
NullPointerException
e
)
{
System
.
err
.
println
(
"Error in spot to ROI conversion"
);
}
if
(
detectionAsROI
==
null
)
{
System
.
err
.
println
(
"Can't convert spot to ROI. spot="
+
spot
);
continue
;
}
// System.out.println( "spot as ROI to test: " + detectionAsROI.getBounds5D() );
for
(
ROI
roi
:
inputROIForMask
.
getValue
())
{
// System.out.println( "roi contenant: " + roi.getBounds5D() );
if
(
roi
.
contains
(
detectionAsROI
))
{
// System.out.println("contains");
continue
detectionList
;
}
}
// System.out.println("don't contains");
detectionResult
.
remove
(
spot
);
}
}
// set outputs.
// binary output: propagate ROIs.
{
Sequence
binarySequence
=
waveletCore
.
getBinarySequence
();
if
(
inputSequenceROIVar
.
getValue
()
!=
null
)
{
for
(
ROI2D
roi
:
inputSequenceROIVar
.
getValue
().
getROI2Ds
())
{
// System.out.println("roi:"+roi);
String
name
=
roi
.
getName
();
ROI2D
roiCopy
=
(
ROI2D
)
roi
.
getCopy
();
roi
.
setName
(
name
);
// because of the bug when coppying roi.
roiCopy
.
setName
(
name
);
// else the name has " copy" in the end of it.
binarySequence
.
addROI
(
roiCopy
);
}
}
binarySpotSequence
.
setValue
(
binarySequence
);
}
// output detection as ROI
{
ArrayList
<
ROI
>
roiList
=
DetectionToROI
.
convertDetectionToROI
(
detectionResult
);
ROI
roi
[]
=
new
ROI
[
roiList
.
size
()];
int
i
=
0
;
for
(
ROI
roiCandidate
:
roiList
)
{
roi
[
i
]
=
roiCandidate
;
i
++;
}
detectionAsROIOut
.
setValue
(
roi
);
}
}
catch
(
InterruptedException
e
)
{
// protocols process interrupted
Thread
.
currentThread
().
interrupt
();
}
}
@Override
public
void
declareInput
(
VarList
inputMap
)
{
inputMap
.
add
(
inputSequenceVar
);
inputMap
.
add
(
detectionMethod
);
inputMap
.
add
(
"input Sequence ROIs"
,
inputSequenceROIVar
);
inputMap
.
add
(
computeWATConsideringROIBoolean
);
inputMap
.
add
(
inputROIForMask
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
inputMap
.
add
(
useScaleBoolean
[
i
]);
}
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
inputMap
.
add
(
scaleParameter
[
i
]);
}
inputMap
.
add
(
force2DWaveletVar
);
}
@Override
public
void
declareOutput
(
VarList
outputMap
)
{
// outputMap.add( outSequence );
// outputMap.add( denoisedSequence );
outputMap
.
add
(
binarySpotSequence
);
outputMap
.
add
(
detectionAsROIOut
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment