Skip to content

Commit

Permalink
Changes to ImageROI and ImageWorker interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Jesus committed Jul 1, 2022
1 parent 695b0b5 commit 93471aa
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 8 deletions.
113 changes: 106 additions & 7 deletions sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageROI.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,97 @@
package pt.ua.dicoogle.sdk.imageworker;

import java.io.File;
import java.net.URI;
import java.util.Objects;

/**
* This object defines an Image ROI.
* It has a physical location defined by an URI.
* It is possible to write the image contents to a file defined by the URI.
* The ROI has an x and y position that identify its origin in the source image.
* The SOPInstanceUID defines where this ROI was extracted from.
*/
public class ImageROI {

public enum FileType {
JPEG (".jpg", "image/jpeg"),
PNG (".png", "image/png");

private final String extension;
private final String mimeType;

private FileType(String s, String mimeType) {
this.extension = s;
this.mimeType = mimeType;
}

public String getExtension() { return extension; }

public String getMimeType() {return mimeType; }
}

private double x;

private double y;

private int width;

private int height;

private URI roi;
private String sopInstanceUID;

private URI uriROI;

public ImageROI(int width, int height, URI roi) {
private FileType fileType;

private ImageROI(URI uriROI){
File f = new File(uriROI);
if(!f.exists())
throw new IllegalArgumentException(String.format("URI %s does not exist", uriROI.getPath()));
this.x = 0;
this.y = 0;
}

public ImageROI(String sopInstanceUID, int width, int height, URI uriROI, FileType fileType) {
this(uriROI);
this.width = width;
this.height = height;
this.roi = roi;
this.uriROI = uriROI;
this.fileType = fileType;
}

public ImageROI(String sopInstanceUID, int x, int y, int width, int height, URI uriROI, FileType fileType) {
this(uriROI);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.uriROI = uriROI;
this.fileType = fileType;
}

public double getX() {
return x;
}

public void setX(double x) {
this.x = x;
}

public double getY() {
return y;
}

public void setY(double y) {
this.y = y;
}

public String getSopInstanceUID() {
return sopInstanceUID;
}

public void setSopInstanceUID(String sopInstanceUID) {
this.sopInstanceUID = sopInstanceUID;
}

public int getWidth() {
Expand All @@ -32,11 +110,32 @@ public void setHeight(int height) {
this.height = height;
}

public URI getRoi() {
return roi;
public URI getUriROI() {
return uriROI;
}

public void setUriROI(URI uriROI) {
this.uriROI = uriROI;
}

public FileType getFileType() {
return fileType;
}

public void setFileType(FileType fileType) {
this.fileType = fileType;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ImageROI imageROI = (ImageROI) o;
return Double.compare(imageROI.x, x) == 0 && Double.compare(imageROI.y, y) == 0 && width == imageROI.width && height == imageROI.height && Objects.equals(sopInstanceUID, imageROI.sopInstanceUID) && Objects.equals(uriROI, imageROI.uriROI);
}

public void setRoi(URI roi) {
this.roi = roi;
@Override
public int hashCode() {
return Objects.hash(x, y, width, height, sopInstanceUID, uriROI);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
import pt.ua.dicoogle.sdk.datastructs.SearchResult;
import pt.ua.dicoogle.sdk.datastructs.dim.BulkAnnotation;

import java.awt.image.BufferedImage;

public interface ImageWorkerInterface extends DicooglePlugin {
public abstract ImageROI extractROI(SearchResult sr, BulkAnnotation annotation);

/**
* Given a search result and one annotation, extract its ROI as a BufferedImage.
* This method does not write the ROI to disk.
* @param sr
* @param annotation
* @return
*/
public abstract BufferedImage extractROI(SearchResult sr, BulkAnnotation annotation);

/**
* Given a search result and a list of annotations, extract the ROIs the annotations define on the image.
* This method will automatically write all ROIs to disk.
* @param sr
* @param annotations
* @return a list of image ROIs defined by the list of annotations
*/
public abstract Iterable<ImageROI> extractROIs(SearchResult sr, Iterable<BulkAnnotation> annotations);
}

0 comments on commit 93471aa

Please sign in to comment.