use of sc.fiji.labkit.ui.models.SegmentationItem in project labkit-ui by juglab.
the class CustomizedSegmentationComponentDemo method initActions.
private void initActions() {
final Holder<SegmentationItem> selectedSegmenter = segmentationModel.segmenterList().selectedSegmenter();
final ImageLabelingModel labelingModel = segmentationModel.imageLabelingModel();
new TrainClassifier(extensible, segmentationModel.segmenterList());
new ClassifierSettingsAction(extensible, segmentationModel.segmenterList());
new ClassifierIoAction(extensible, segmentationModel.segmenterList());
new LabelingIoAction(extensible, labelingModel);
new AddLabelingIoAction(extensible, labelingModel.labeling());
new SegmentationExportAction(extensible, labelingModel);
new ResetViewAction(extensible, labelingModel);
new BatchSegmentAction(extensible, selectedSegmenter);
new SegmentationAsLabelAction(extensible, segmentationModel);
new BitmapImportExportAction(extensible, labelingModel);
new LabelEditAction(extensible, false, new ColoredLabelsModel(labelingModel));
MeasureConnectedComponents.addAction(extensible, labelingModel);
labelingComponent.addShortcuts(extensible.getShortCuts());
}
use of sc.fiji.labkit.ui.models.SegmentationItem in project labkit-ui by juglab.
the class CustomizedSegmentationComponentDemo method onSaveResultsClicked.
private void onSaveResultsClicked(ActionEvent actionEvent) {
SegmentationItem selectedSegmenter = segmentationModel.segmenterList().selectedSegmenter().get();
if (selectedSegmenter == null || !selectedSegmenter.isTrained()) {
JOptionPane.showMessageDialog(null, "Please select a segmentation algoritm and train it");
return;
}
ImageLabelingModel imageLabeling = segmentationModel.imageLabelingModel();
RandomAccessibleInterval<ShortType> segmentation = selectedSegmenter.results(imageLabeling).segmentation();
ParallelUtils.runInOtherThread(() -> {
ParallelUtils.populateCachedImg(segmentation, new SwingProgressWriter(null, "Calculate Entire Segmentation"));
JOptionPane.showMessageDialog(null, "Calculation completed");
BdvFunctions.show(segmentation, "Segmentation").setDisplayRange(0, 1);
});
}
use of sc.fiji.labkit.ui.models.SegmentationItem in project labkit-ui by juglab.
the class MultiChannelMovieDemo method testInputImageImageForSegmentation.
@Test
public void testInputImageImageForSegmentation() {
DatasetInputImage inputImage = inputImage5d();
SegmentationModel segmentationModel = new DefaultSegmentationModel(new Context(), inputImage);
SegmentationItem segmenter = segmentationModel.segmenterList().addSegmenter(PixelClassificationPlugin.create());
Labeling labeling1 = labeling5d();
segmentationModel.imageLabelingModel().labeling().set(labeling1);
segmenter.train(Collections.singletonList(new ValuePair<>(inputImage.imageForSegmentation(), labeling1)));
RandomAccessibleInterval<ShortType> result = segmenter.results(segmentationModel.imageLabelingModel()).segmentation();
Labeling labeling = labeling5d();
LoopBuilder.setImages(labeling, result).forEachPixel((l, r) -> {
if (l.contains("foreground"))
assertEquals(1, r.get());
if (l.contains("background"))
assertEquals(0, r.get());
});
}
use of sc.fiji.labkit.ui.models.SegmentationItem in project labkit-ui by juglab.
the class SegmentationUseCaseTest method testMultiChannel.
@Test
public void testMultiChannel() throws InterruptedException {
Img<UnsignedByteType> img = ArrayImgs.unsignedBytes(new byte[] { -1, 0, -1, 0, -1, -1, 0, 0 }, 2, 2, 2);
ImgPlus<UnsignedByteType> imgPlus = new ImgPlus<>(img, "Image", new AxisType[] { Axes.X, Axes.Y, Axes.CHANNEL });
DatasetInputImage inputImage = new DatasetInputImage(imgPlus, BdvShowable.wrap(Views.hyperSlice(img, 2, 0)));
Labeling labeling = getLabeling();
SegmentationModel segmentationModel = new DefaultSegmentationModel(new Context(), inputImage);
ImageLabelingModel imageLabelingModel = segmentationModel.imageLabelingModel();
imageLabelingModel.labeling().set(labeling);
SegmentationItem segmenter = segmentationModel.segmenterList().addSegmenter(PixelClassificationPlugin.create());
segmenter.train(Collections.singletonList(new ValuePair<>(imgPlus, imageLabelingModel.labeling().get())));
RandomAccessibleInterval<ShortType> result = segmenter.results(imageLabelingModel).segmentation();
Iterator<ShortType> it = Views.iterable(result).iterator();
assertEquals(1, it.next().get());
assertEquals(0, it.next().get());
assertEquals(0, it.next().get());
assertEquals(0, it.next().get());
assertTrue(Intervals.equals(new FinalInterval(2, 2), result));
}
use of sc.fiji.labkit.ui.models.SegmentationItem in project labkit-ui by juglab.
the class SegmentationUseCaseTest method test.
@Test
public void test() {
ImgPlus<UnsignedByteType> image = new ImgPlus<>(ArrayImgs.unsignedBytes(new byte[] { 1, 1, 2, 2 }, 2, 2));
InputImage inputImage = new DatasetInputImage(image);
SegmentationModel segmentationModel = new DefaultSegmentationModel(new Context(), inputImage);
addLabels(segmentationModel.imageLabelingModel());
SegmentationPlugin plugin = PixelClassificationPlugin.create();
SegmentationItem segmenter = segmentationModel.segmenterList().addSegmenter(plugin);
segmenter.train(Collections.singletonList(new ValuePair<>(image, segmentationModel.imageLabelingModel().labeling().get())));
RandomAccessibleInterval<ShortType> result = segmenter.results(segmentationModel.imageLabelingModel()).segmentation();
List<Integer> list = new ArrayList<>();
Views.iterable(result).forEach(x -> list.add(x.getInteger()));
assertEquals(Arrays.asList(1, 1, 0, 0), list);
}
Aggregations