Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Layered Segmentation. Done by Nikhil.
authorlingutln <lingutln@localhost>
Mon, 9 Jan 2012 23:35:10 +0000 (23:35 +0000)
committerlingutln <lingutln@localhost>
Mon, 9 Jan 2012 23:35:10 +0000 (23:35 +0000)
svn path=/; revision=257

Annotation/.classpath
Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java
Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java
Annotation/src/ie/dcu/segment/SegmentationContext.java
Annotation/src/ie/dcu/segment/SegmentationMask.java
Annotation/src/ie/dcu/segment/SegmentationObject.java [deleted file]
Annotation/src/ie/dcu/segment/painters/CombinedPainter.java

index dae8e98e88b39b4f09341cfcc41b0d028f908a0a..22412b6c9a2c02f608af7c008e1447f0c9cabf62 100644 (file)
@@ -1,11 +1,11 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<classpath>\r
-       <classpathentry kind="src" path="src"/>\r
-       <classpathentry excluding="src/" kind="src" path=""/>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
-       <classpathentry kind="lib" path="C:/Users/Nikhil/workspace/image_annotation/lib/jface.jar"/>\r
-       <classpathentry kind="lib" path="C:/Users/Nikhil/workspace/image_annotation/lib/swt-win.jar"/>\r
-       <classpathentry kind="lib" path="C:/Users/Nikhil/workspace/Annotation/library/commons-lang3-3.1.jar"/>\r
-       <classpathentry kind="lib" path="C:/Users/Nikhil/workspace/Annotation/library/json.jar"/>\r
-       <classpathentry kind="output" path="bin"/>\r
-</classpath>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry excluding="src/" kind="src" path=""/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="lib" path="/home/lingutln/workspace/Annotation/library/commons-lang3-3.1.jar"/>
+       <classpathentry kind="lib" path="/home/lingutln/workspace/Annotation/library/jface.jar"/>
+       <classpathentry kind="lib" path="/home/lingutln/workspace/Annotation/library/json.jar"/>
+       <classpathentry kind="lib" path="/home/lingutln/workspace/Annotation/library/swt-gtk-64.jar"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
index 8e7f715bf72b2cbd403741feed1b155a61c32571..833790682efaf334a8bc95c00bdec9902f22297d 100644 (file)
@@ -479,6 +479,7 @@ public class SegmentationView extends Composite {
        public void formSegmetationObject() {
        
                view.getContext().formSegmentationObject();
+               updateToolStates();
        }
        
        
@@ -832,7 +833,14 @@ public class SegmentationView extends Composite {
                        Tool.ZoomOut.action.setEnabled(canZoomOut());
                        Tool.ZoomOriginal.action.setEnabled(canZoomOriginal());
                        Tool.ZoomBestFit.action.setEnabled(canZoomBestFit());
-                       comboLabel.setEnabled(CanLabel());
+                       if(view.getContext() != null)
+                       {
+                               comboLabel.setEnabled((view.getContext().getMasks().size() > 0));
+                       }
+                       else
+                       {
+                               comboLabel.setEnabled(false);
+                       }
                        assign.setEnabled(canZoomBestFit() & !(comboLabel.getText().isEmpty()));
                        Tool.Foreground.action.setChecked(isAnnotatingForeground());
                        Tool.Background.action.setChecked(isAnnotatingBackground());
@@ -1036,21 +1044,30 @@ public class SegmentationView extends Composite {
        private final MouseListener popupListener = new MouseListener() {
 
                public void mouseUp(MouseEvent event) {
-                       PopUpLabelDialog dialog = new PopUpLabelDialog(getShell());
-                       PopUpLabelDialog.Result result = dialog.open();
-                       if (result != null) {
-                               String lab = null;
-                               if(result.comboText.indexOf('{') != -1)
-                       {
-                                       lab = result.comboText.substring(0,result.comboText.indexOf('{')-1);
-                       }
-                       else
-                       {
-                               lab = result.comboText;
-                       }
-                       System.out.println("selected"+lab);
-                               comboLabel.setText(result.comboText);
-                               execute(Tool.AssignButton, null);
+                       // For the right click
+                       if(event.button == 3)
+                       {
+                               PopUpLabelDialog dialog = new PopUpLabelDialog(getShell());
+                               PopUpLabelDialog.Result result = dialog.open();
+                               if (result != null) 
+                               {
+                                       String lab = null;
+                                       if(result.comboText.indexOf('{') != -1)
+                               {
+                                               lab = result.comboText.substring(0,result.comboText.indexOf('{')-1);
+                               }
+                               else
+                               {
+                                       lab = result.comboText;
+                               }
+                               System.out.println("selected"+lab);
+                                       comboLabel.setText(result.comboText);
+                                       execute(Tool.AssignButton, null);
+                               }
+                       }
+                       else if(event.button == 1)
+                       {
+                               System.out.println("Mouse left click");
                        }
                }
                public void mouseDown(MouseEvent e) 
index c3e578e0b3b7b6f2eb3ef19a636c414332ead198..2a8644eae2ade94a8ec20aa92cd55889d58609c5 100644 (file)
@@ -204,7 +204,8 @@ public class AnnotatedImageControl extends Composite {
        }
        
        public boolean CanLabel() {
-               if (ctx != null) {
+               if (ctx != null) 
+               {
                        return ctx.getAnnotations().canLabel();
                }
                return false;
index 4b31b1b2d229b4ae11c93ebe286ee28c3034360a..7a0171dd09ad43bef3dbf4e846fcdc9c98b5d590 100644 (file)
@@ -45,11 +45,11 @@ public class SegmentationContext {
        /**
         * For storing independent Segmentation objects
         */
-       private ArrayList<SegmentationObject> segmentationObjects;
+       private ArrayList<SegmentationMask> segmentationMaskObjects;
        
        // lazy create (use getters for these fields)
        private AnnotationManager annotations;
-       private SegmentationObject segmentObject;
+       private SegmentationMask segmentationMask;
        private Image image;
        private Rectangle bounds;
 
@@ -65,7 +65,7 @@ public class SegmentationContext {
        private SegmentationContext(ImageData imageData, File file) {
                this.imageData = imageData;
                this.file = file;
-               segmentationObjects = new ArrayList<SegmentationObject>();
+               segmentationMaskObjects = new ArrayList<SegmentationMask>();
        }
 
        /**
@@ -122,7 +122,7 @@ public class SegmentationContext {
                }
                return annotations;
        }
-
+       
        /**
         * Returns the bounds of the current image and segmentation mask.
         * 
@@ -136,41 +136,32 @@ public class SegmentationContext {
        }
        
        public final void formSegmentationObject() {
-               segmentationObjects.add(segmentObject);
-               System.out.println("Number of objects formed : "+segmentationObjects.size());
-               /*if(segmentationObjects.size()>1)
-               {
-                       //assert (segmentationObjects.get(0).equals(segmentationObjects.get(1))) : true;
-                       if(segmentationObjects.get(0).equals(segmentationObjects.get(1)))
-                       {
-                               System.out.println("Both objects are equal");
-                       }
-                       else
-                       {
-                               System.out.println("Both objects are not equal");
-                       }
-               }*/
+               segmentationMaskObjects.add(segmentationMask);
+               
                // Making a new segmentationObject after storing the current SegmentationObject
-               segmentObject = null;
-       //      System.out.println("Annotation size : "+annotations.count());
+               segmentationMask = null;
                annotations.clear();
        }
        
        /**
-        * Returns the current segmentation mask.
+        * Returns the current segmentation mask which has not yet been made into an object.
         * 
         * @return A {@link SegmentationMask} instance. Returns the latest mask which hasn't yet turned into an object.
         */
        public SegmentationMask getMask() {
-               if (segmentObject == null) {
-                       segmentObject = new SegmentationObject(getBounds());
+               if (segmentationMask == null) {
+                       segmentationMask = new SegmentationMask(getBounds());
                }
-               return segmentObject;
+               return segmentationMask;
        }
-       
-       public ArrayList<SegmentationObject> getMasks() {
+       /**
+        * All the masks excluding the current mask (i.e the mask which has not yet been made into a Segmentation object)
+        * @return
+        * A list of SegmentationMasks excluding the current mask which has not yet been made into a Segmentation object 
+        */
+       public ArrayList<SegmentationMask> getMasks() {
                
-               return segmentationObjects;
+               return segmentationMaskObjects;
        }
        
        /**
@@ -322,7 +313,7 @@ public class SegmentationContext {
                        new FileInputStream(file)));
 
                ImageData imageData = null;
-               SegmentationObject segmentObject = null;
+               SegmentationMask segmentMaskObject = null;
                AnnotationManager annotations = null;
 
                try {
@@ -335,7 +326,7 @@ public class SegmentationContext {
                                        imageData = SwtUtils.loadImageData(in);
 
                                } else if (name.equals("mask.png")) {
-                                       segmentObject = (SegmentationObject) SegmentationMask.read(in);
+                                       segmentMaskObject = SegmentationMask.read(in);
 
                                } else if (name.equals("markup.dat")) {
                                        annotations = new AnnotationManager();
@@ -353,7 +344,7 @@ public class SegmentationContext {
                        throw new IOException("No image found in context file");
                }
 
-               if (segmentObject == null) {
+               if (segmentMaskObject == null) {
                        throw new IOException("No mask found in context file");
                }
 
@@ -363,7 +354,7 @@ public class SegmentationContext {
 
                SegmentationContext ctx = new SegmentationContext(imageData, file);
 
-               ctx.segmentObject = segmentObject;
+               ctx.segmentationMask = segmentMaskObject;
                ctx.annotations = annotations;
 
                return ctx;
index 74f0138db353c62289f079a5d3d7192e3d33d133..28211a90e7d2cd2c8395f0fbc70bbc8c08672a6d 100644 (file)
@@ -330,7 +330,7 @@ public class SegmentationMask extends ByteMatrix{
                ImageData data = loadImageData(file);
                
                // Create compatible mask
-               SegmentationMask mask = new SegmentationObject(data.width, data.height);
+               SegmentationMask mask = new SegmentationMask(data.width, data.height);
                
                // Load data into the mask
                mask.load(data);
@@ -353,7 +353,7 @@ public class SegmentationMask extends ByteMatrix{
                ImageData data = loadImageData(in);
                
                // Create compatible mask
-               SegmentationMask mask = new SegmentationObject(data.width, data.height);
+               SegmentationMask mask = new SegmentationMask(data.width, data.height);
                
                // Load data into the mask
                mask.load(data);
diff --git a/Annotation/src/ie/dcu/segment/SegmentationObject.java b/Annotation/src/ie/dcu/segment/SegmentationObject.java
deleted file mode 100644 (file)
index 8b53bf5..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-package ie.dcu.segment;
-
-import org.eclipse.swt.graphics.Rectangle;
-
-
-/**
- * Class that represents a independent segmentation mask.
- * 
- * A segmentation mask is a two dimensional matrix of byte values. It is used
- * to represents which pixels in an image that are part of the foreground, and 
- * which are part of the background.
- * 
- * @author Nikhil
- */
-
-public final class SegmentationObject extends SegmentationMask{
-
-       private static final long serialVersionUID = 8321845179859248904L;
-       private int layerNumber;
-       
-       public SegmentationObject(int width, int height) {
-               super(width, height);
-               // TODO Auto-generated constructor stub
-       }
-       
-       public SegmentationObject(Rectangle bounds) {
-               this(bounds.width, bounds.height);
-               // TODO Auto-generated constructor stub
-       }
-               
-       
-}
index b3af16e8da324916362146aad2e94a6b42f4bc7d..77c519f12dfe3023e1a11e1082c5a8363ca3c458 100644 (file)
@@ -32,26 +32,40 @@ public class CombinedPainter implements SegmentationPainter {
        }
        
        public void paint(SegmentationContext ctx, ObservableImage im) {
-
+               
                GC gc = im.beginPaint();
 
                // Paint image
                gc.drawImage(ctx.getImage(), 0, 0);
 
-               // Paint mask
-               if(ctx.getMasks().size() != 0)
+               // Paint masks
+               if(ctx.getMasks().size() > 0)
                {
                        // For drawing all the previous masks.
                        for(SegmentationMask mask : ctx.getMasks())
                        {
-                               createVisibleMask(mask);
-                               gc.drawImage(maskImage, 0, 0);
+                               // Blending of background pixel values while pasting the last mask only
+                               if(ctx.getMasks().indexOf(mask) == ctx.getMasks().size()-1)
+                               {
+                                       createVisibleMask(mask,true);
+                                       gc.drawImage(maskImage, 0, 0);
+                               }
+                               else
+                               {
+                                       createVisibleMask(mask,false);
+                                       gc.drawImage(maskImage, 0, 0);
+                               }
                        }
+                       // Current mask which has not yet been made into an object
+                       createVisibleMask(ctx.getMask(),false);
+                       gc.drawImage(maskImage, 0, 0);
                }
-               // Drawing the current mask
-               createVisibleMask(ctx.getMask());
-               gc.drawImage(maskImage, 0, 0);
-               
+               else
+               {
+                       createVisibleMask(ctx.getMask(),true);
+                       gc.drawImage(maskImage, 0, 0);
+               }
+                               
                // Paint all annotations
                ctx.getAnnotations().paint(im);
                
@@ -61,7 +75,7 @@ public class CombinedPainter implements SegmentationPainter {
 
        
        
-       private void createVisibleMask(SegmentationMask mask) {
+       private void createVisibleMask(SegmentationMask mask,boolean isFirstObject) {
                dispose();
                if (isNewMaskDataRequired(mask.getBounds())) {
                        maskData = createMaskData(mask.getBounds());
@@ -75,7 +89,7 @@ public class CombinedPainter implements SegmentationPainter {
                                
                                switch (mask.values[i]) {
                                case SegmentationMask.BACKGROUND:
-                                       alpha = (byte) 128;
+                                       alpha = isFirstObject ? (byte) 128 : (byte) 0;
                                        index = 2;
                                        break;
                                case SegmentationMask.FOREGROUND:
@@ -107,62 +121,6 @@ public class CombinedPainter implements SegmentationPainter {
        }
        
        
-       
-       
-       // Temp code, will remove
-       
-       /*private void createVisibleMask(ArrayList<SegmentationMask> masks) {
-               dispose();
-               System.out.println("In loop"+masks.size());
-               for (SegmentationMask mask : masks) {
-                       if (isNewMaskDataRequired(mask.getBounds())) {
-                               maskData = createMaskData(mask.getBounds());
-                       } 
-                       
-                       // Blit in pixels
-                       for (int y = 0, i = 0; y < mask.height; y++) {
-                               int rowOffset = y * maskData.bytesPerLine;
-                               for (int x = 0; x < mask.width; x++) {
-                                       byte alpha, index;
-                                       
-                                       switch (mask.values[i]) {
-                                       case SegmentationMask.BACKGROUND:
-                                               alpha = (byte) 128;
-                                               index = 2;
-                                               break;
-                                       case SegmentationMask.FOREGROUND:
-                                               alpha = (byte) 128;
-                                               index = 1;
-                                               break;
-                                       default:
-                                               alpha = 0;
-                                               index = 0;
-                                               break;
-                                       }
-                                                                       
-                                       // The SWT ImageData buffer doesn't usually have it's rows aligned
-                                       // contiguously in memory (i.e. there are > width bytes per scan-line in
-                                       // the buffer), so we can't directly copy in at the same index as the
-                                       // mask.
-                                       maskData.data[x + rowOffset] = index;
-                                       
-                                       // However, the alpha data is always aligned correctly
-                                       maskData.alphaData[i] = alpha;
-                                       
-                                       // Next location in the mask
-                                       i++;
-                               }
-                       }
-               }
-               
-               // Create new mask
-               maskImage = new Image(Display.getCurrent(), maskData);
-       }*/
-       
-       
-       
-       
-       
        private boolean isNewMaskDataRequired(Rectangle bounds) {
                if (maskData == null) {
                        return true;