Search in sources :

Example 11 with DatasetInputImage

use of sc.fiji.labkit.ui.inputimage.DatasetInputImage in project labkit-ui by juglab.

the class CustomCachedImageFactoryDemo method main.

public static void main(String... args) {
    final ImagePlus imp = new ImagePlus("https://imagej.nih.gov/ij/images/FluorescentCells.jpg");
    ImgPlus<?> image = VirtualStackAdapter.wrap(imp);
    DefaultSegmentationModel segmentationModel = new DefaultSegmentationModel(SingletonContext.getInstance(), new DatasetInputImage(image));
    segmentationModel.extensionPoints().setCachedSegmentationImageFactory(CustomCachedImageFactoryDemo::noCacheFactory);
    segmentationModel.extensionPoints().setCachedPredictionImageFactory(CustomCachedImageFactoryDemo::noCacheFactory);
    LabkitFrame.show(segmentationModel, "Custom Cached Image Factory Demo, That actually uses no cahce.");
}
Also used : DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) ImagePlus(ij.ImagePlus)

Example 12 with DatasetInputImage

use of sc.fiji.labkit.ui.inputimage.DatasetInputImage in project labkit-ui by juglab.

the class DefaultSegmentationModelTest method testLoadClassifierWithDifferentLabels.

@Test
public void testLoadClassifierWithDifferentLabels() throws IOException {
    // This test reproduced a NoSuchElementException, that appeared when
    // a classifier is loaded, that was trained on a label, whose name
    // doesn't appear in the current labeling.
    // create model
    DatasetInputImage image = new DatasetInputImage(ArrayImgs.unsignedBytes(1, 1));
    SegmentationModel model = new DefaultSegmentationModel(new Context(), image);
    // train classifier
    Labeling labeling = model.imageLabelingModel().labeling().get();
    List<Label> labels = labeling.getLabels();
    Views.iterable(labeling.getRegion(labels.get(0))).forEach(BitType::setOne);
    SegmentationItem item = model.segmenterList().addSegmenter(PixelClassificationPlugin.create());
    item.train(Collections.singletonList(new ValuePair<>(image.imageForSegmentation(), labeling)));
    // save classifier
    File tmpFile = File.createTempFile("model", ".classifier");
    tmpFile.deleteOnExit();
    item.saveModel(tmpFile.getAbsolutePath());
    // remove labels
    for (Label label : labels) labeling.removeLabel(label);
    // open classifier
    item.openModel(tmpFile.getAbsolutePath());
}
Also used : Context(org.scijava.Context) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) BitType(net.imglib2.type.logic.BitType) ValuePair(net.imglib2.util.ValuePair) Label(sc.fiji.labkit.ui.labeling.Label) Labeling(sc.fiji.labkit.ui.labeling.Labeling) File(java.io.File) Test(org.junit.Test)

Example 13 with DatasetInputImage

use of sc.fiji.labkit.ui.inputimage.DatasetInputImage in project labkit-ui by juglab.

the class SegmentImageWithLabkitPlugin method run.

@Override
public void run() {
    TrainableSegmentationSegmenter segmenter = new TrainableSegmentationSegmenter(context);
    segmenter.setUseGpu(use_gpu);
    segmenter.openModel(segmenter_file.getAbsolutePath());
    ImgPlus<?> imgPlus = new DatasetInputImage(input).imageForSegmentation();
    Img<ShortType> outputImg = useCache(imgPlus) ? calculateOnCachedImg(segmenter, imgPlus) : calculateOnArrayImg(segmenter, imgPlus);
    output = datasetService.create(outputImg);
}
Also used : TrainableSegmentationSegmenter(sc.fiji.labkit.ui.segmentation.weka.TrainableSegmentationSegmenter) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) ShortType(net.imglib2.type.numeric.integer.ShortType)

Example 14 with DatasetInputImage

use of sc.fiji.labkit.ui.inputimage.DatasetInputImage in project labkit-ui by juglab.

the class CziOpenerDemo method run.

public static void run(String filename) {
    CziOpener opener = new CziOpener(new ProgressWriterConsole());
    DatasetInputImage out = opener.openWithDialog(filename);
    out.showable().show("Image", BdvOptions.options().is2D());
}
Also used : DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) ProgressWriterConsole(bdv.export.ProgressWriterConsole)

Example 15 with DatasetInputImage

use of sc.fiji.labkit.ui.inputimage.DatasetInputImage in project labkit-ui by juglab.

the class DefaultSegmentationModelTest method testListener.

@Test
public void testListener() {
    BitType flag = new BitType(false);
    SegmenterListModel model = new DefaultSegmentationModel(new Context(), new DatasetInputImage(ArrayImgs.unsignedBytes(100, 100))).segmenterList();
    model.segmenters().notifier().addListener(flag::setOne);
    assertFalse(flag.get());
    assertEquals(0, model.segmenters().get().size());
    model.addSegmenter(PixelClassificationPlugin.create());
    assertTrue(flag.get());
    assertEquals(1, model.segmenters().get().size());
    flag.set(false);
    SegmentationItem item = model.segmenters().get().get(0);
    model.remove(item);
    assertTrue(flag.get());
    assertEquals(0, model.segmenters().get().size());
}
Also used : Context(org.scijava.Context) BitType(net.imglib2.type.logic.BitType) DatasetInputImage(sc.fiji.labkit.ui.inputimage.DatasetInputImage) Test(org.junit.Test)

Aggregations

DatasetInputImage (sc.fiji.labkit.ui.inputimage.DatasetInputImage)25 Context (org.scijava.Context)10 Test (org.junit.Test)7 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)6 ImagePlus (ij.ImagePlus)5 DefaultSegmentationModel (sc.fiji.labkit.ui.models.DefaultSegmentationModel)5 ShortType (net.imglib2.type.numeric.integer.ShortType)4 ValuePair (net.imglib2.util.ValuePair)4 Labeling (sc.fiji.labkit.ui.labeling.Labeling)4 ImageLabelingModel (sc.fiji.labkit.ui.models.ImageLabelingModel)4 SegmentationModel (sc.fiji.labkit.ui.models.SegmentationModel)4 ImgPlus (net.imagej.ImgPlus)3 AxisType (net.imagej.axis.AxisType)3 SegmentationItem (sc.fiji.labkit.ui.models.SegmentationItem)3 File (java.io.File)2 IOException (java.io.IOException)2 ARGBType (net.imglib2.type.numeric.ARGBType)2 ProgressWriter (bdv.export.ProgressWriter)1 ProgressWriterConsole (bdv.export.ProgressWriterConsole)1 AbstractSource (bdv.util.AbstractSource)1