From ac20dd32d050094a2394ac33f5479e511467ba4a Mon Sep 17 00:00:00 2001 From: prd Date: Sat, 24 Dec 2016 01:19:33 +0100 Subject: [PATCH 1/2] refactor packages & introduce OpenIMAJ --- imageprocessing/pom.xml | 5 ++++ .../imagej/ImageJRectExample.java} | 6 ++-- .../openimaj/OpenIMAJRectExample.java | 28 +++++++++++++++++++ .../swing/SwingRectExample.java} | 6 ++-- 4 files changed, 39 insertions(+), 6 deletions(-) rename imageprocessing/src/main/java/{imagej/DrawRect.java => com/baeldung/imageprocessing/imagej/ImageJRectExample.java} (68%) create mode 100644 imageprocessing/src/main/java/com/baeldung/imageprocessing/openimaj/OpenIMAJRectExample.java rename imageprocessing/src/main/java/{swing/DrawRect.java => com/baeldung/imageprocessing/swing/SwingRectExample.java} (85%) diff --git a/imageprocessing/pom.xml b/imageprocessing/pom.xml index 36e1b57028..6c1cdff2e3 100644 --- a/imageprocessing/pom.xml +++ b/imageprocessing/pom.xml @@ -14,6 +14,11 @@ ij 1.51h + + org.openimaj + core-image + 1.3.5 + \ No newline at end of file diff --git a/imageprocessing/src/main/java/imagej/DrawRect.java b/imageprocessing/src/main/java/com/baeldung/imageprocessing/imagej/ImageJRectExample.java similarity index 68% rename from imageprocessing/src/main/java/imagej/DrawRect.java rename to imageprocessing/src/main/java/com/baeldung/imageprocessing/imagej/ImageJRectExample.java index 53354d89d0..893eb262f7 100644 --- a/imageprocessing/src/main/java/imagej/DrawRect.java +++ b/imageprocessing/src/main/java/com/baeldung/imageprocessing/imagej/ImageJRectExample.java @@ -1,4 +1,4 @@ -package imagej; +package com.baeldung.imageprocessing.imagej; import ij.IJ; import ij.ImagePlus; @@ -6,9 +6,9 @@ import ij.process.ImageProcessor; import java.awt.*; -public class DrawRect { +public class ImageJRectExample { public static void main(String[] args) { - ImagePlus imp = IJ.openImage(DrawRect.class.getClassLoader().getResource("lena.jpg").getPath()); + ImagePlus imp = IJ.openImage(ImageJRectExample.class.getClassLoader().getResource("lena.jpg").getPath()); drawRect(imp); imp.show(); } diff --git a/imageprocessing/src/main/java/com/baeldung/imageprocessing/openimaj/OpenIMAJRectExample.java b/imageprocessing/src/main/java/com/baeldung/imageprocessing/openimaj/OpenIMAJRectExample.java new file mode 100644 index 0000000000..52f6c524a8 --- /dev/null +++ b/imageprocessing/src/main/java/com/baeldung/imageprocessing/openimaj/OpenIMAJRectExample.java @@ -0,0 +1,28 @@ +package com.baeldung.imageprocessing.openimaj; + +import org.openimaj.image.DisplayUtilities; +import org.openimaj.image.ImageUtilities; +import org.openimaj.image.MBFImage; +import org.openimaj.math.geometry.point.Point2d; +import org.openimaj.math.geometry.point.Point2dImpl; +import org.openimaj.math.geometry.shape.Polygon; + +import java.io.IOException; +import java.util.Arrays; + +public class OpenIMAJRectExample { + public static void main(String[] args) throws IOException { + MBFImage image = ImageUtilities.readMBF(OpenIMAJRectExample.class.getClassLoader().getResource("lena.jpg")); + drawRectangle(image); + DisplayUtilities.display(image); + } + + private static void drawRectangle(MBFImage image) { + Point2d tl = new Point2dImpl(10, 10); + Point2d bl = new Point2dImpl(10, image.getHeight()-10); + Point2d br = new Point2dImpl(image.getWidth()-10, image.getHeight()-10); + Point2d tr = new Point2dImpl(image.getWidth() - 10, 10); + Polygon polygon = new Polygon(Arrays.asList(tl, bl, br, tr)); + image.drawPolygon(polygon, 4, new Float[] {new Float(0),new Float(0),new Float(255.0)}); + } +} diff --git a/imageprocessing/src/main/java/swing/DrawRect.java b/imageprocessing/src/main/java/com/baeldung/imageprocessing/swing/SwingRectExample.java similarity index 85% rename from imageprocessing/src/main/java/swing/DrawRect.java rename to imageprocessing/src/main/java/com/baeldung/imageprocessing/swing/SwingRectExample.java index 8fc7f5184e..08edd6ee83 100644 --- a/imageprocessing/src/main/java/swing/DrawRect.java +++ b/imageprocessing/src/main/java/com/baeldung/imageprocessing/swing/SwingRectExample.java @@ -1,4 +1,4 @@ -package swing; +package com.baeldung.imageprocessing.swing; import javax.imageio.ImageIO; import javax.swing.*; @@ -7,7 +7,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -public class DrawRect { +public class SwingRectExample { public static void main(String[] args) throws IOException { BufferedImage image = loadImage(); drawRectangle(image); @@ -15,7 +15,7 @@ public class DrawRect { } private static BufferedImage loadImage() throws IOException { - String imagePath = DrawRect.class.getClassLoader().getResource("lena.jpg").getPath(); + String imagePath = SwingRectExample.class.getClassLoader().getResource("lena.jpg").getPath(); return ImageIO.read(new File(imagePath)); } From e04a15bc8ee4d3f76b68755b3bc3861526aff6cd Mon Sep 17 00:00:00 2001 From: prd Date: Sat, 24 Dec 2016 01:27:48 +0100 Subject: [PATCH 2/2] refactor pom for image processing --- imageprocessing/pom.xml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/imageprocessing/pom.xml b/imageprocessing/pom.xml index 6c1cdff2e3..20fb70edd9 100644 --- a/imageprocessing/pom.xml +++ b/imageprocessing/pom.xml @@ -8,17 +8,21 @@ imageprocessing 1.0-SNAPSHOT + + 1.3.5 + 1.51h + + net.imagej ij - 1.51h + ${ij.version} org.openimaj core-image - 1.3.5 + ${core-image.version} - \ No newline at end of file