Search in sources :

Example 1 with SegmentationModel

use of sc.fiji.labkit.ui.models.SegmentationModel 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 2 with SegmentationModel

use of sc.fiji.labkit.ui.models.SegmentationModel 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 3 with SegmentationModel

use of sc.fiji.labkit.ui.models.SegmentationModel 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)

Example 4 with SegmentationModel

use of sc.fiji.labkit.ui.models.SegmentationModel in project labkit-ui by juglab.

the class GarbageCollectionTest method addSegmentationComponent.

private void addSegmentationComponent(JFrame frame) {
    SegmentationModel segmentationModel = new DefaultSegmentationModel(context, new DatasetInputImage(ArrayImgs.bytes(10, 10)));
    SegmentationComponent component = new SegmentationComponent(frame, segmentationModel, false);
    frame.add(component);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            component.close();
        }
    });
}
Also used : DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) SegmentationModel(sc.fiji.labkit.ui.models.SegmentationModel)

Example 5 with SegmentationModel

use of sc.fiji.labkit.ui.models.SegmentationModel in project labkit-ui by juglab.

the class LabkitFrame method showForImage.

public static LabkitFrame showForImage(Context context, final InputImage inputImage) {
    if (context == null)
        context = SingletonContext.getInstance();
    final SegmentationModel model = new DefaultSegmentationModel(context, inputImage);
    model.imageLabelingModel().labeling().set(InitialLabeling.initialLabeling(context, inputImage));
    return show(model, inputImage.imageForSegmentation().getName());
}
Also used : DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) DefaultSegmentationModel(sc.fiji.labkit.ui.models.DefaultSegmentationModel) SegmentationModel(sc.fiji.labkit.ui.models.SegmentationModel)

Aggregations

DefaultSegmentationModel (sc.fiji.labkit.ui.models.DefaultSegmentationModel)5 SegmentationModel (sc.fiji.labkit.ui.models.SegmentationModel)5 DatasetInputImage (sc.fiji.labkit.ui.inputimage.DatasetInputImage)4 ShortType (net.imglib2.type.numeric.integer.ShortType)3 ValuePair (net.imglib2.util.ValuePair)3 Test (org.junit.Test)3 Context (org.scijava.Context)3 SegmentationItem (sc.fiji.labkit.ui.models.SegmentationItem)3 ImgPlus (net.imagej.ImgPlus)2 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)2 Labeling (sc.fiji.labkit.ui.labeling.Labeling)2 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 ArrayList (java.util.ArrayList)1 FinalInterval (net.imglib2.FinalInterval)1 InputImage (sc.fiji.labkit.ui.inputimage.InputImage)1 ImageLabelingModel (sc.fiji.labkit.ui.models.ImageLabelingModel)1 SegmentationPlugin (sc.fiji.labkit.ui.segmentation.SegmentationPlugin)1