From be5f6a89fbd525c947d80397606cc4a2e2eb7088 Mon Sep 17 00:00:00 2001 From: lingutln Date: Mon, 12 Mar 2012 18:56:49 +0000 Subject: [PATCH] Latest Commits. Done by Nikhil. svn path=/; revision=310 --- .../resources/config/actions.properties | 4 +- .../ie/dcu/apps/ist/actions/OpenAction.java | 17 ++++- .../apps/ist/export/imagemap/Exporter.java | 10 ++- .../ie/dcu/segment/SegmentationContext.java | 74 +++++++++++++++++++ .../src/ie/dcu/segment/SegmentationMask.java | 14 ++++ .../segment/annotate/AnnotationManager.java | 1 - 6 files changed, 113 insertions(+), 7 deletions(-) diff --git a/Annotation/resources/config/actions.properties b/Annotation/resources/config/actions.properties index f2ddcb0..ecffedd 100644 --- a/Annotation/resources/config/actions.properties +++ b/Annotation/resources/config/actions.properties @@ -1,7 +1,7 @@ OpenAction.dialog.text=Open an image or saved context -OpenAction.dialog.filter.exts=*.jpg;*.jpeg;*.png;*.gif;*.bmp;*.ctx -OpenAction.dialog.filter.text=Image and Context Files +OpenAction.dialog.filter.exts=*.jpg;*.jpeg;*.png;*.gif;*.bmp;*.ctx;*.imgmap +OpenAction.dialog.filter.text=Image,imagemap and Context Files SaveAction.dialog.text=Save Segmentation Context SaveAction.dialog.filter.exts=*.ctx diff --git a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java index 5c956b6..797723a 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java @@ -17,6 +17,11 @@ public class OpenAction extends AppAction { private FileDialog dialog; + /** + * The file extension given to a this object when it is saved on a disk + */ + public static final String IMGMAP_EXTENSION = ".imgmap"; + public OpenAction(ActionManager m) { super(m); } @@ -39,8 +44,14 @@ public class OpenAction extends AppAction { // Load context window.setContext(SegmentationContext.load(file)); status("Opened segmentation context %s successfully", name); - } else { - + } + else if (name.toLowerCase().endsWith(IMGMAP_EXTENSION)) + { + // Load Imagemap from Disk + window.setContext(SegmentationContext.loadImageMap(file)); + status("Opened segmentation context %s successfully", name); + } + else { // Create context window.setContext(SegmentationContext.create(file)); status("Opened image file %s successfully", name); @@ -83,7 +94,7 @@ public class OpenAction extends AppAction { if (dialog == null) { dialog = new FileDialog(window.getShell(), SWT.OPEN | SWT.SHEET); dialog.setText(property("OpenAction.dialog.text")); - //dialog.setFilterExtensions(getFilters()); + dialog.setFilterExtensions(getFilters()); dialog.setFilterNames(getFilterNames()); } } diff --git a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java index 9017f93..42fcf05 100644 --- a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java +++ b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java @@ -169,6 +169,13 @@ public class Exporter { // writing to the folder ImageIO.write(im, "png", output); + + // Saving the marked up annotations + ZipEntry markupData = new ZipEntry("markup-"+mask.layerNumber+".dat"); + + out.putNextEntry(markupData); + + mask.getAnnotations().save(out); } } @@ -236,7 +243,8 @@ public class Exporter { if (effect != null) { - String basename = FileUtils.removeExtension(imageFile); + //String basename = FileUtils.removeExtension(imageFile); + String basename = "segment"; for (int i = 0; i < trace.size(); i++) { String filename = String.format("%s-%d.png", basename, layerNumber); preloads.add(filename); diff --git a/Annotation/src/ie/dcu/segment/SegmentationContext.java b/Annotation/src/ie/dcu/segment/SegmentationContext.java index b7c0950..094d46e 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationContext.java +++ b/Annotation/src/ie/dcu/segment/SegmentationContext.java @@ -146,6 +146,7 @@ public class SegmentationContext { disableAllSegments(); // Set needsHighlighting True for the current segment. currentSegmentMask.enabled = true; + currentSegmentMask.setAnnotations(getAnnotations()); segmentationMaskObjects.add(currentSegmentMask); // Making a new segmentationObject after storing the current SegmentationObject currentSegmentMask = null; @@ -355,6 +356,7 @@ public class SegmentationContext { out.putNextEntry(entry); // Store the markup + System.out.println("Near seg context save"); getAnnotations().save(out); // close entry @@ -368,6 +370,7 @@ public class SegmentationContext { // Set new filename this.file = file; } + System.out.println("After all the saving is done"); } /** @@ -431,6 +434,77 @@ public class SegmentationContext { return ctx; } + + + /** + * Load a ImageMap object from the disk. + * + * @param file + * A file containing the Imagemap. + * @return A new segmentation context object. + * @throws IOException + * If there is an error loading the segmentation context file. + */ + public static SegmentationContext loadImageMap(File file) throws IOException { + ZipInputStream in = new ZipInputStream(new BufferedInputStream( + new FileInputStream(file))); + + ImageData imageData = null; + SegmentationMask segmentMask = null; + AnnotationManager annotations = null; + + try { + ZipEntry entry; + while ((entry = in.getNextEntry()) != null) { + + String name = entry.getName(); + + if (name.equals("image.png")) { + System.out.println("Loading Original image"); + imageData = SwtUtils.loadImageData(in); + + } else if (name.startsWith("segment")) { + String[] temp; + temp = name.split("-"); + System.out.println("Temp array coming as "+temp[0]+" and "+temp[1]); + //segmentObject = (SegmentationObject) SegmentationMask.read(in); + + } else if (name.equals("markup.dat")) { + annotations = new AnnotationManager(); + annotations.load(in); + } + System.out.println("File name is : "+name); + + in.closeEntry(); + } + + } finally { + in.close(); + } + + if (imageData == null) { + throw new IOException("No image found in context file"); + } + + if (segmentMask == null) { + throw new IOException("No mask found in context file"); + } + + if (annotations == null) { + throw new IOException("No annotations found in context file"); + } + + SegmentationContext ctx = new SegmentationContext(imageData, file); + + ctx.currentSegmentMask = segmentMask; + ctx.annotations = annotations; + + return ctx; + } + + + + /** * Static method that checks if the given file appears to be a segmentation * context file. diff --git a/Annotation/src/ie/dcu/segment/SegmentationMask.java b/Annotation/src/ie/dcu/segment/SegmentationMask.java index bc9c35e..32ba6e1 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationMask.java +++ b/Annotation/src/ie/dcu/segment/SegmentationMask.java @@ -1,6 +1,7 @@ package ie.dcu.segment; import ie.dcu.matrix.ByteMatrix; +import ie.dcu.segment.annotate.AnnotationManager; import java.io.*; @@ -51,6 +52,9 @@ public class SegmentationMask extends ByteMatrix{ * The height of the segmentation mask. */ public final int height; + + // Annotations associated with Mask objects + private AnnotationManager annotations; //The total number of layers formed. public static int numberOfLayers; @@ -213,6 +217,16 @@ public class SegmentationMask extends ByteMatrix{ return new Rectangle(0, 0, width, height); } + public void setAnnotations(AnnotationManager annotations) { + this.annotations = annotations; + } + + public AnnotationManager getAnnotations() { + if (annotations == null) { + annotations = new AnnotationManager(); + } + return annotations; + } /** * Returns a string representation of the mask. diff --git a/Annotation/src/ie/dcu/segment/annotate/AnnotationManager.java b/Annotation/src/ie/dcu/segment/annotate/AnnotationManager.java index 92ff8e4..5cdbb96 100644 --- a/Annotation/src/ie/dcu/segment/annotate/AnnotationManager.java +++ b/Annotation/src/ie/dcu/segment/annotate/AnnotationManager.java @@ -261,7 +261,6 @@ public class AnnotationManager { } public void save(OutputStream o) throws IOException { - DataOutputStream out = new DataOutputStream( new BufferedOutputStream(o)); -- 2.34.1