Skip to content

Commit

Permalink
update the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Apr 20, 2024
1 parent e2ef3b8 commit 365c221
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/ai/nets/samj/communication/model/EfficientSAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.imglib2.util.Cast;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -156,6 +157,25 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
}
}

@Override
/**
* {@inheritDoc}
*/
public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D,
Rectangle zoomedRectangle) throws IOException, RuntimeException, InterruptedException {
try {
List<int[]> list = listOfPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, zoomedRectangle, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
}
}

@Override
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.imglib2.util.Cast;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -158,6 +159,22 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
}
}

@Override
public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D,
Rectangle zoomedRectangle) throws IOException, RuntimeException, InterruptedException {
try {
List<int[]> list = listOfPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, zoomedRectangle, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
}
}

@Override
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.imglib2.util.Cast;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -160,6 +161,22 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
}
}

@Override
public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D,
Rectangle zoomedRectangle) throws IOException, RuntimeException, InterruptedException {
try {
List<int[]> list = listOfPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, zoomedRectangle, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
}
}

@Override
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.imglib2.util.Cast;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -160,6 +161,22 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
}
}

@Override
public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D,
Rectangle zoomedRectangle) throws IOException, RuntimeException, InterruptedException {
try {
List<int[]> list = listOfPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, zoomedRectangle, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
}
}

@Override
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.imglib2.util.Cast;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -160,6 +161,22 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
}
}

@Override
public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D,
Rectangle zoomedRectangle) throws IOException, RuntimeException, InterruptedException {
try {
List<int[]> list = listOfPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, zoomedRectangle, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
}
}

@Override
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.imglib2.util.Cast;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -161,6 +162,22 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
}
}

@Override
public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D,
Rectangle zoomedRectangle) throws IOException, RuntimeException, InterruptedException {
try {
List<int[]> list = listOfPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, zoomedRectangle, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
}
}

@Override
/**
* {@inheritDoc}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/ai/nets/samj/communication/model/SAMModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ai.nets.samj.communication.model;

import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;

Expand Down Expand Up @@ -98,6 +99,22 @@ public interface SAMModel {
*/
List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D) throws IOException, RuntimeException, InterruptedException;

/**
* Get a 2D segmentation/annotation using two lists of points as the prompts.
* @param listOfPoints2D
* List of points that make reference to the instance of interest
* @param listOfNegPoints2D
* list of points that makes reference to something that is not the instance of interest. This
* points make reference to the background
* @param zoomedRectangle
* rectangle that specifies the area that is being zoomed in.It will be the area encoded.
* @return a list of polygons that represent the edges of each of the masks segmented by the model
* @throws IOException if any of the files needed to run the Python script is missing
* @throws RuntimeException if there is any error running the Python process
* @throws InterruptedException if the process in interrupted
*/
List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<Localizable> listOfNegPoints2D, Rectangle zoomedRectangle) throws IOException, RuntimeException, InterruptedException;

/**
* Get a 2D segmentation/annotation using a bounding box as the prompt.
* @param boundingBox2D
Expand Down

0 comments on commit 365c221

Please sign in to comment.