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
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);
}
// 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);
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());
}
}
// 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);
}
}
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);
disableAllSegments();
// Set needsHighlighting <code>True</code> for the current segment.
currentSegmentMask.enabled = true;
+ currentSegmentMask.setAnnotations(getAnnotations());
segmentationMaskObjects.add(currentSegmentMask);
// Making a new segmentationObject after storing the current SegmentationObject
currentSegmentMask = null;
out.putNextEntry(entry);
// Store the markup
+ System.out.println("Near seg context save");
getAnnotations().save(out);
// close entry
// Set new filename
this.file = file;
}
+ System.out.println("After all the saving is done");
}
/**
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.
package ie.dcu.segment;
import ie.dcu.matrix.ByteMatrix;
+import ie.dcu.segment.annotate.AnnotationManager;
import java.io.*;
* 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;
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.
}
public void save(OutputStream o) throws IOException {
-
DataOutputStream out = new DataOutputStream(
new BufferedOutputStream(o));