From 60bda6c32716c3e6a350fb91d8379223fffe58ad Mon Sep 17 00:00:00 2001 From: preecej Date: Wed, 10 Oct 2012 23:10:35 +0000 Subject: [PATCH] Trac #197 and 282 svn path=/; revision=398 --- .../src/ie/dcu/apps/ist/Application.java | 2 +- .../ist/actions/ExportImageMapAction.java | 2 +- .../ie/dcu/apps/ist/actions/OpenAction.java | 4 +-- .../ie/dcu/apps/ist/actions/SaveAction.java | 4 +-- .../apps/ist/export/imagemap/Exporter.java | 31 +++++++++++-------- .../ie/dcu/segment/SegmentationContext.java | 13 ++++---- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Annotation/src/ie/dcu/apps/ist/Application.java b/Annotation/src/ie/dcu/apps/ist/Application.java index e8aa61e..2442867 100644 --- a/Annotation/src/ie/dcu/apps/ist/Application.java +++ b/Annotation/src/ie/dcu/apps/ist/Application.java @@ -19,7 +19,7 @@ import static ie.dcu.util.OsUtils.*; public class Application { public static final String APP_ID = "ist"; public static final String APP_NAME = "SIA (Semantic Image Annotator)"; - public static final String APP_VERSION = "0.2 (beta)"; + public static final String APP_VERSION = "0.2.1 (beta)"; public static final String APP_RESOURCE_DIR = "resources"; /** diff --git a/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java b/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java index be8654c..d5481d7 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java @@ -43,7 +43,7 @@ public class ExportImageMapAction extends AppAction{ BufferedImage image = ImageConverter.convert(ctx.getImageData()); // Setup exporter - Exporter exporter = new Exporter(image); + Exporter exporter = new Exporter(image, ctx); exporter.setEffect(result.effect); exporter.setHtmlFile(result.html); diff --git a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java index 40a1f12..54568f8 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/OpenAction.java @@ -45,7 +45,7 @@ public class OpenAction extends AppAction { // clear the decks window.getView().resetView(); - if (SegmentationContext.isContextFile(file)) { + if (SegmentationContext.isContextFile(file)) { // JP - minority case (opening an zip file to re-annotate) // Load context window.setContext(SegmentationContext.load(file)); status("Opened segmentation context %s successfully", name); @@ -56,7 +56,7 @@ public class OpenAction extends AppAction { window.setContext(SegmentationContext.loadImageMap(file)); status("Opened segmentation context %s successfully", name); } - else { // JP - majority of cases (opening an img or zip file to annotate) + else { // JP - majority of cases (opening an img file to annotate) // Create context window.setContext(SegmentationContext.create(file)); status("Opened image file %s successfully", name); diff --git a/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java b/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java index 47fa3a5..6e60aba 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java @@ -49,7 +49,7 @@ public class SaveAction extends AppAction { BufferedImage image = ImageConverter.convert(ctx.getImageData()); // Setup exporter - Exporter exporter = new Exporter(image); + Exporter exporter = new Exporter(image, ctx); // save the annotated zip file String zipFile = result.zipFile; @@ -100,7 +100,7 @@ public class SaveAction extends AppAction { BufferedImage image = ImageConverter.convert(ctx.getImageData()); // Setup exporter - Exporter exporter = new Exporter(image); + Exporter exporter = new Exporter(image, ctx); // save the annotated zip file String zipFile = result.zipFile; 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 b8d89cd..7eb8618 100644 --- a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java +++ b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java @@ -1,7 +1,9 @@ package ie.dcu.apps.ist.export.imagemap; +import ie.dcu.apps.ist.Application; import ie.dcu.apps.ist.views.SegmentationView; import ie.dcu.image.ContourTracer; +import ie.dcu.segment.SegmentationContext; import ie.dcu.segment.SegmentationMask; import java.awt.Polygon; @@ -35,12 +37,14 @@ public class Exporter { private String zipFile = ""; private String imageFile = "image.png"; private String imageName = "image"; + private String origImageFileName = ""; private String objectDescription = ""; private String objectLink = ""; private AreaShape exportShape = AreaShape.Polygon; - public Exporter(BufferedImage image) { + public Exporter(BufferedImage image, SegmentationContext ctx) { this.image = image; + this.origImageFileName = ctx.getFile().getName(); } public RolloverEffect getEffect() { @@ -127,7 +131,7 @@ public class Exporter { try { // Low (fast) compression.. most of data is PNG compressed anyway - out.setLevel(0); + out.setLevel(9); out.flush(); // Create an entry for the image ZipEntry entryImage = new ZipEntry(imageFile); @@ -172,7 +176,7 @@ public class Exporter { } // Low (fast) compression.. most of data is PNG compressed anyway - out.setLevel(0); + //out.setLevel(0); // Create an entry for the image ZipEntry entryMaskImage = new ZipEntry(preloads.get(i).toString()); @@ -240,8 +244,8 @@ public class Exporter { } finally { - // Close - out.close(); + out.flush(); + out.close(); // close the output zip file stream (makes the zip file) } } @@ -249,12 +253,7 @@ public class Exporter { { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(o)); byte[] intensityValues = mask.values; - boolean[] values = new boolean[intensityValues.length]; - for(int x =0; x < intensityValues.length;x++) - { - values[x] = (intensityValues[x] == 2 ? false:true); - out.writeBoolean(values[x]); - } + out.write(intensityValues); } private void saveMetadata(OutputStream o, List masks) throws IOException @@ -268,10 +267,16 @@ public class Exporter { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); + Element rootElement = document.createElement("image_data"); document.appendChild(rootElement); - - Element imageElement = document.createElement("image_filename"); + + Element versionElement = document.createElement("sia_version"); + versionElement.setTextContent(Application.APP_VERSION); + rootElement.appendChild(versionElement); + + Element imageElement = document.createElement("orig_image_filename"); + imageElement.setTextContent(this.origImageFileName); rootElement.appendChild(imageElement); Element speciesElement = document.createElement("species"); diff --git a/Annotation/src/ie/dcu/segment/SegmentationContext.java b/Annotation/src/ie/dcu/segment/SegmentationContext.java index 90cd1dc..cb2dce0 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationContext.java +++ b/Annotation/src/ie/dcu/segment/SegmentationContext.java @@ -599,16 +599,16 @@ public class SegmentationContext { { DataInputStream input = new DataInputStream(new BufferedInputStream(in)); int length = width * height; - boolean[] intensity = new boolean[length]; + //boolean[] intensity = new boolean[length]; + byte[] intensity = new byte[length]; int index = 0; boolean EOF = false; - // see code in export and something to do with sizes Array index out of bounds exception do it today completely while(!EOF) { try { - intensity[index] = input.readBoolean(); + intensity[index] = (byte)input.read(); } catch(Exception e) { @@ -617,14 +617,13 @@ public class SegmentationContext { index = index+1; } int i = 0; - for (int x=0;x