diff --git a/src/main/java/ai/nets/samj/gui/MainGUI.java b/src/main/java/ai/nets/samj/gui/MainGUI.java index 292c925..7432fb6 100644 --- a/src/main/java/ai/nets/samj/gui/MainGUI.java +++ b/src/main/java/ai/nets/samj/gui/MainGUI.java @@ -13,6 +13,9 @@ import ai.nets.samj.gui.components.ModelDrawerPanel.ModelDrawerPanelListener; import ai.nets.samj.ui.ConsumerInterface; import ai.nets.samj.utils.Constants; +import net.imglib2.RandomAccessibleInterval; +import net.imglib2.type.NativeType; +import net.imglib2.type.numeric.RealType; import net.imglib2.util.Cast; import javax.swing.*; @@ -97,7 +100,13 @@ public MainGUI(List modelList, ConsumerInterface consumer) { chkInstant.addActionListener(e -> setInstantPromptsEnabled(this.chkInstant.isSelected())); chkRoiManager.addActionListener(e -> consumer.enableAddingToRoiManager(chkRoiManager.isSelected())); retunLargest.addActionListener(e -> cmbModels.getSelectedModel().setReturnOnlyBiggest(retunLargest.isSelected())); - btnBatchSAMize.addActionListener(e -> consumer.exportImageLabeling()); + btnBatchSAMize.addActionListener(e -> { + try { + batchSAMize(); + } catch (IOException | RuntimeException | InterruptedException e1) { + e1.printStackTrace(); + } + }); close.addActionListener(e -> dispose()); help.addActionListener(e -> consumer.exportImageLabeling()); @@ -430,6 +439,11 @@ private void toggleDrawer() { repaint(); } + private < T extends RealType< T > & NativeType< T > > void batchSAMize() throws IOException, RuntimeException, InterruptedException { + RandomAccessibleInterval rai = Cast.unchecked(((ComboBoxItem) cmbPresets.getSelectedItem()).getImageAsImgLib2()); + this.consumer.addPolygonsFromGUI(this.cmbModels.getSelectedModel().fetch2dSegmentationFromMask(rai)); + } + private void updatePresetsCard() { CardLayout cl = (CardLayout) (cardPanel.getLayout()); cl.show(cardPanel, PRESET_STR); diff --git a/src/main/java/ai/nets/samj/ui/ConsumerInterface.java b/src/main/java/ai/nets/samj/ui/ConsumerInterface.java index bdccac9..8ec993e 100644 --- a/src/main/java/ai/nets/samj/ui/ConsumerInterface.java +++ b/src/main/java/ai/nets/samj/ui/ConsumerInterface.java @@ -22,6 +22,7 @@ import java.awt.Polygon; import java.util.List; +import ai.nets.samj.annotation.Mask; import ai.nets.samj.communication.model.SAMModel; import ai.nets.samj.gui.components.ComboBoxItem; @@ -65,6 +66,8 @@ public abstract class ConsumerInterface { */ public abstract void exportImageLabeling(); + public abstract void addPolygonsFromGUI(List masks); + public abstract void activateListeners(); public abstract void deactivateListeners();