// the HWST operator has to be registered within JAI
WatershedTranformDescriptor.register();
// load the source image, e.g. by using JAI's "fileload":
PlanarImage image = JAI.create("fileload", "sourcImage.jpg");
// parameters are encapsulated as a ParameterBlock object
ParameterBlock pb = new ParameterBlock();
pb.addSource(image); // set source image!
pb.add(200); // side length of a tile (here: 200x200)
pb.add(16d); // minimal gradient between neighboring segments for HWST
pb.add(20); // minimal segment size
pb.add(3); // size of the convolution kernel for smoothing (hier: 3x3)
pb.add(1); // turn scaling option ON
pb.add(120000); // set the optimal processing resolution to 400x300 (400*300 = 120000 px)
// the SEQUENCE of the parameters is IMPORTANT
// executes the HWST
RenderedOp sOp = JAI.create("HierarchicalWatershedTranform", pb, null);
// retrieves the segmentation result as a MergedSegmentMap objekt from the resulting RenderedOp's
// "segmentMap" property
MergedSegmentMap map = (MergedSegmentMap) sOp.getProperty("segmentMap");
// to visualize the result you can generate a mosaic image by this instruction
BufferedImage resultImage = map.getMosaicImage();
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To use the HWST operator, the following code is necessary:
...............................................
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import java.awt.image.renderable.ParameterBlock;
import info.wurzinger.jaiOp.hwst.WatershedTranformDescriptor;
import info.wurzinger.segmenting.elements.segment.MergedSegmentMap;
// the HWST operator has to be registered within JAI
WatershedTranformDescriptor.register();
// load the source image, e.g. by using JAI's "fileload":
PlanarImage image = JAI.create("fileload", "sourcImage.jpg");
// parameters are encapsulated as a ParameterBlock object
ParameterBlock pb = new ParameterBlock();
pb.addSource(image); // set source image!
pb.add(200); // side length of a tile (here: 200x200)
pb.add(16d); // minimal gradient between neighboring segments for HWST
pb.add(20); // minimal segment size
pb.add(3); // size of the convolution kernel for smoothing (hier: 3x3)
pb.add(1); // turn scaling option ON
pb.add(120000); // set the optimal processing resolution to 400x300 (400*300 = 120000 px)
// the SEQUENCE of the parameters is IMPORTANT
// executes the HWST
RenderedOp sOp = JAI.create("HierarchicalWatershedTranform", pb, null);
// retrieves the segmentation result as a MergedSegmentMap objekt from the resulting RenderedOp's
// "segmentMap" property
MergedSegmentMap map = (MergedSegmentMap) sOp.getProperty("segmentMap");
// to visualize the result you can generate a mosaic image by this instruction
BufferedImage resultImage = map.getMosaicImage();