Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bioimage Analysis
ROI blocks
Commits
b61dc6b6
Commit
b61dc6b6
authored
Jun 02, 2021
by
danyfel80
Browse files
First implementation of watershed block
parent
f86d8706
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
b61dc6b6
...
...
@@ -3,9 +3,11 @@
bin/
build/
target/
workspace/
*.iml
*.eml
*.jar
.classpath
.project
export.jardesc
setting.xml
src/main/java/plugins/stef/roi/bloc/RoiBlocks.java
View file @
b61dc6b6
package
plugins.stef.roi.bloc
;
import
icy.main.Icy
;
import
icy.plugin.PluginDescriptor
;
import
icy.plugin.PluginLauncher
;
import
icy.plugin.PluginLoader
;
import
icy.plugin.abstract_.Plugin
;
import
icy.plugin.interface_.PluginLibrary
;
import
plugins.adufour.protocols.Protocols
;
/**
* Bundle of blocks (Protocols) to perform different operations on ROI (Region Of Interest).<br>
...
...
@@ -21,5 +26,10 @@ import icy.plugin.interface_.PluginLibrary;
*/
public
class
RoiBlocks
extends
Plugin
implements
PluginLibrary
{
//
public
static
void
main
(
String
[]
args
)
{
Icy
.
main
(
args
);
PluginLauncher
.
start
(
PluginLoader
.
getPlugin
(
Protocols
.
class
.
getName
()));
}
}
src/main/java/plugins/stef/roi/bloc/op/SeparateROIWatershed.java
0 → 100644
View file @
b61dc6b6
/**
*
*/
package
plugins.stef.roi.bloc.op
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
icy.plugin.abstract_.Plugin
;
import
icy.plugin.interface_.PluginBundled
;
import
icy.plugin.interface_.PluginLibrary
;
import
icy.roi.ROI
;
import
icy.roi.ROIUtil
;
import
icy.system.IcyHandledException
;
import
icy.type.dimension.Dimension3D
;
import
icy.type.dimension.Dimension5D
;
import
icy.type.rectangle.Rectangle5D
;
import
plugins.adufour.blocks.tools.roi.ROIBlock
;
import
plugins.adufour.blocks.util.VarList
;
import
plugins.adufour.vars.lang.VarROIArray
;
import
plugins.stef.roi.bloc.RoiBlocks
;
/**
* This block allows users to use the watershed separation function available on the ROI tools on the ribbon of Icy.
* ROIs are supposed to be 2D ROIs.
* Seed ROIs are optional. If no seeds are provided, they will be computed using a distance map on the image.
* The result ROIs will be the separated components.
* The result seed ROIs will be either the input seeds or the ones computed by the algorithm.
*
* @author Daniel Felipe Gonzalez Obando
*/
public
class
SeparateROIWatershed
extends
Plugin
implements
ROIBlock
,
PluginLibrary
,
PluginBundled
{
protected
VarROIArray
varInTargetRois
;
protected
VarROIArray
varInSeedRois
;
@Override
public
void
declareInput
(
VarList
inputMap
)
{
varInTargetRois
=
new
VarROIArray
(
"ROI(s)"
);
varInSeedRois
=
new
VarROIArray
(
"Seed ROI(s)"
);
inputMap
.
add
(
"inputRois"
,
varInTargetRois
);
inputMap
.
add
(
"inputSeeds"
,
varInSeedRois
);
}
protected
VarROIArray
varOutRois
;
protected
VarROIArray
varOutSeeds
;
@Override
public
void
declareOutput
(
VarList
outputMap
)
{
varOutRois
=
new
VarROIArray
(
"Separated ROI(s)"
);
varOutSeeds
=
new
VarROIArray
(
"Seed ROI(s)"
);
outputMap
.
add
(
"outputRois"
,
varOutRois
);
outputMap
.
add
(
"outputSeeds"
,
varOutSeeds
);
}
@Override
public
void
run
()
{
final
ROI
[]
rois
=
varInTargetRois
.
getValue
();
final
ROI
[]
seeds
=
varInSeedRois
.
getValue
();
List
<
ROI
>
result
=
new
ArrayList
<
ROI
>();
List
<
ROI
>
seedList
;
if
(
rois
!=
null
)
{
try
{
if
(
seeds
!=
null
&&
seeds
.
length
>
0
)
{
seedList
=
Arrays
.
asList
(
seeds
);
result
=
ROIUtil
.
computeWatershedSeparation
(
Arrays
.
asList
(
rois
),
seedList
,
getDimensionSize
(
rois
),
new
Dimension3D
.
Double
(
1
d
,
1
d
,
1
d
));
}
else
{
seedList
=
new
ArrayList
<
ROI
>();
result
=
ROIUtil
.
computeWatershedSeparation
(
Arrays
.
asList
(
rois
),
getDimensionSize
(
rois
),
new
Dimension3D
.
Double
(
1
d
,
1
d
,
1
d
),
seedList
);
}
}
catch
(
Exception
e
)
{
throw
new
IcyHandledException
(
"Error on watershed separation: "
+
e
.
getMessage
(),
e
);
}
varOutRois
.
setValue
(
result
.
toArray
(
new
ROI
[
result
.
size
()]));
varOutSeeds
.
setValue
(
seedList
.
toArray
(
new
ROI
[
seedList
.
size
()]));
}
}
private
Dimension5D
getDimensionSize
(
ROI
[]
rois
)
{
Dimension5D
.
Double
dims
=
new
Dimension5D
.
Double
();
for
(
ROI
roi
:
rois
)
{
Rectangle5D
roiBounds
=
roi
.
getBounds5D
();
dims
.
sizeX
=
Math
.
max
(
dims
.
sizeX
,
roiBounds
.
getMaxX
()
+
10
);
dims
.
sizeY
=
Math
.
max
(
dims
.
sizeY
,
roiBounds
.
getMaxY
()
+
10
);
dims
.
sizeZ
=
Math
.
max
(
dims
.
sizeZ
,
roiBounds
.
getMaxZ
());
dims
.
sizeT
=
Math
.
max
(
dims
.
sizeT
,
roiBounds
.
getMaxT
());
dims
.
sizeC
=
Math
.
max
(
dims
.
sizeC
,
roiBounds
.
getMaxC
());
}
if
(!
Double
.
isFinite
(
dims
.
sizeX
)
||
dims
.
sizeX
==
0
)
dims
.
sizeX
=
1
;
if
(!
Double
.
isFinite
(
dims
.
sizeY
)
||
dims
.
sizeY
==
0
)
dims
.
sizeY
=
1
;
if
(!
Double
.
isFinite
(
dims
.
sizeZ
)
||
dims
.
sizeZ
==
0
)
dims
.
sizeZ
=
1
;
if
(!
Double
.
isFinite
(
dims
.
sizeT
)
||
dims
.
sizeT
==
0
)
dims
.
sizeT
=
1
;
if
(!
Double
.
isFinite
(
dims
.
sizeC
)
||
dims
.
sizeC
==
0
)
dims
.
sizeC
=
1
;
return
dims
;
}
@Override
public
String
getMainPluginClassName
()
{
return
RoiBlocks
.
class
.
getName
();
}
}
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