Search in sources :

Example 1 with SegmentationItem

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());
}
Also used : ResetViewAction(sc.fiji.labkit.ui.actions.ResetViewAction) LabelEditAction(sc.fiji.labkit.ui.actions.LabelEditAction) ColoredLabelsModel(sc.fiji.labkit.ui.models.ColoredLabelsModel) BatchSegmentAction(sc.fiji.labkit.ui.actions.BatchSegmentAction) SegmentationExportAction(sc.fiji.labkit.ui.actions.SegmentationExportAction) ClassifierIoAction(sc.fiji.labkit.ui.actions.ClassifierIoAction) ClassifierSettingsAction(sc.fiji.labkit.ui.actions.ClassifierSettingsAction) ImageLabelingModel(sc.fiji.labkit.ui.models.ImageLabelingModel) AddLabelingIoAction(sc.fiji.labkit.ui.actions.AddLabelingIoAction) LabelingIoAction(sc.fiji.labkit.ui.actions.LabelingIoAction) AddLabelingIoAction(sc.fiji.labkit.ui.actions.AddLabelingIoAction) SegmentationItem(sc.fiji.labkit.ui.models.SegmentationItem) BitmapImportExportAction(sc.fiji.labkit.ui.actions.BitmapImportExportAction) SegmentationAsLabelAction(sc.fiji.labkit.ui.actions.SegmentationAsLabelAction) TrainClassifier(sc.fiji.labkit.ui.segmentation.TrainClassifier)

Example 2 with SegmentationItem

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);
    });
}
Also used : ImageLabelingModel(sc.fiji.labkit.ui.models.ImageLabelingModel) SegmentationItem(sc.fiji.labkit.ui.models.SegmentationItem) ShortType(net.imglib2.type.numeric.integer.ShortType) SwingProgressWriter(sc.fiji.labkit.ui.utils.progress.SwingProgressWriter)

Example 3 with SegmentationItem

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());
    });
}
Also used : Context(org.scijava.Context) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) SegmentationItem(sc.fiji.labkit.ui.models.SegmentationItem) ValuePair(net.imglib2.util.ValuePair) ShortType(net.imglib2.type.numeric.integer.ShortType) Labeling(sc.fiji.labkit.ui.labeling.Labeling) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) SegmentationModel(sc.fiji.labkit.ui.models.SegmentationModel) Test(org.junit.Test)

Example 4 with SegmentationItem

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));
}
Also used : Context(org.scijava.Context) ImgPlus(net.imagej.ImgPlus) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) ValuePair(net.imglib2.util.ValuePair) ShortType(net.imglib2.type.numeric.integer.ShortType) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) SegmentationModel(sc.fiji.labkit.ui.models.SegmentationModel) ImageLabelingModel(sc.fiji.labkit.ui.models.ImageLabelingModel) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) SegmentationItem(sc.fiji.labkit.ui.models.SegmentationItem) FinalInterval(net.imglib2.FinalInterval) Labeling(sc.fiji.labkit.ui.labeling.Labeling) Test(org.junit.Test)

Example 5 with SegmentationItem

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);
}
Also used : Context(org.scijava.Context) SegmentationPlugin(sc.fiji.labkit.ui.segmentation.SegmentationPlugin) ImgPlus(net.imagej.ImgPlus) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) ValuePair(net.imglib2.util.ValuePair) ShortType(net.imglib2.type.numeric.integer.ShortType) ArrayList(java.util.ArrayList) InputImage(sc.fiji.labkit.ui.inputimage.InputImage) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) SegmentationModel(sc.fiji.labkit.ui.models.SegmentationModel) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) SegmentationItem(sc.fiji.labkit.ui.models.SegmentationItem) Test(org.junit.Test)

Aggregations

SegmentationItem (sc.fiji.labkit.ui.models.SegmentationItem)8 ShortType (net.imglib2.type.numeric.integer.ShortType)4 ImageLabelingModel (sc.fiji.labkit.ui.models.ImageLabelingModel)4 ValuePair (net.imglib2.util.ValuePair)3 Test (org.junit.Test)3 Context (org.scijava.Context)3 DatasetInputImage (sc.fiji.labkit.ui.inputimage.DatasetInputImage)3 DefaultSegmentationModel (sc.fiji.labkit.ui.models.DefaultSegmentationModel)3 SegmentationModel (sc.fiji.labkit.ui.models.SegmentationModel)3 ArrayList (java.util.ArrayList)2 ImgPlus (net.imagej.ImgPlus)2 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)2 Labeling (sc.fiji.labkit.ui.labeling.Labeling)2 ColoredLabelsModel (sc.fiji.labkit.ui.models.ColoredLabelsModel)2 TrainClassifier (sc.fiji.labkit.ui.segmentation.TrainClassifier)2 File (java.io.File)1 FinalInterval (net.imglib2.FinalInterval)1 AddLabelingIoAction (sc.fiji.labkit.ui.actions.AddLabelingIoAction)1 BatchSegmentAction (sc.fiji.labkit.ui.actions.BatchSegmentAction)1 BitmapImportExportAction (sc.fiji.labkit.ui.actions.BitmapImportExportAction)1