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.");
}
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());
}
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);
}
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());
}
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());
}
Aggregations