Search in sources :

Example 1 with SegmentationPlugin

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

use of sc.fiji.labkit.ui.segmentation.SegmentationPlugin in project labkit-ui by juglab.

the class SegmenterPanel method showAddSegmenterPopupMenu.

private void showAddSegmenterPopupMenu() {
    SegmentationPluginService pluginService = segmentationModel.context().service(SegmentationPluginService.class);
    List<SegmentationPlugin> plugins = pluginService.getSegmentationPlugins();
    JPopupMenu menu = new JPopupMenu();
    for (SegmentationPlugin plugin : plugins) {
        JMenuItem menuItem = new JMenuItem(plugin.getTitle());
        menuItem.addActionListener(ignore -> addSegmenter(plugin));
        menu.add(menuItem);
    }
    menu.show(addSegmenterButton, 0, addSegmenterButton.getHeight());
}
Also used : SegmentationPlugin(sc.fiji.labkit.ui.segmentation.SegmentationPlugin) SegmentationPluginService(sc.fiji.labkit.ui.segmentation.SegmentationPluginService)

Example 3 with SegmentationPlugin

use of sc.fiji.labkit.ui.segmentation.SegmentationPlugin in project labkit-ui by juglab.

the class AddSegmenterPanel method addButtons.

private void addButtons(SegmenterListModel segmenterListModel, JPanel list) {
    Context context = segmenterListModel.context();
    SegmentationPluginService pluginService = context.service(SegmentationPluginService.class);
    for (SegmentationPlugin sp : pluginService.getSegmentationPlugins()) {
        JButton button = new JButton(sp.getTitle());
        button.addActionListener(ignore -> {
            segmenterListModel.addSegmenter(sp);
        });
        list.add(button, "grow, wrap");
    }
}
Also used : SingletonContext(sc.fiji.labkit.pixel_classification.utils.SingletonContext) Context(org.scijava.Context) SegmentationPlugin(sc.fiji.labkit.ui.segmentation.SegmentationPlugin) SegmentationPluginService(sc.fiji.labkit.ui.segmentation.SegmentationPluginService)

Aggregations

SegmentationPlugin (sc.fiji.labkit.ui.segmentation.SegmentationPlugin)3 Context (org.scijava.Context)2 SegmentationPluginService (sc.fiji.labkit.ui.segmentation.SegmentationPluginService)2 ArrayList (java.util.ArrayList)1 ImgPlus (net.imagej.ImgPlus)1 ShortType (net.imglib2.type.numeric.integer.ShortType)1 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)1 ValuePair (net.imglib2.util.ValuePair)1 Test (org.junit.Test)1 SingletonContext (sc.fiji.labkit.pixel_classification.utils.SingletonContext)1 DatasetInputImage (sc.fiji.labkit.ui.inputimage.DatasetInputImage)1 InputImage (sc.fiji.labkit.ui.inputimage.InputImage)1 DefaultSegmentationModel (sc.fiji.labkit.ui.models.DefaultSegmentationModel)1 SegmentationItem (sc.fiji.labkit.ui.models.SegmentationItem)1 SegmentationModel (sc.fiji.labkit.ui.models.SegmentationModel)1