From 93471aa2b24173cadb12a8f51377e46605c95835 Mon Sep 17 00:00:00 2001 From: Rui Jesus Date: Fri, 1 Jul 2022 18:17:52 +0100 Subject: [PATCH] Changes to ImageROI and ImageWorker interfaces --- .../ua/dicoogle/sdk/imageworker/ImageROI.java | 113 ++++++++++++++++-- .../sdk/imageworker/ImageWorkerInterface.java | 19 ++- 2 files changed, 124 insertions(+), 8 deletions(-) diff --git a/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageROI.java b/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageROI.java index 4ac85de70..337953fbf 100644 --- a/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageROI.java +++ b/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageROI.java @@ -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() { @@ -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); } } diff --git a/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageWorkerInterface.java b/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageWorkerInterface.java index b0e4b62eb..5b8d6a8fc 100644 --- a/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageWorkerInterface.java +++ b/sdk/src/main/java/pt/ua/dicoogle/sdk/imageworker/ImageWorkerInterface.java @@ -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 extractROIs(SearchResult sr, Iterable annotations); }