diff --git a/imageprocessing/pom.xml b/imageprocessing/pom.xml index 36e1b57028..20fb70edd9 100644 --- a/imageprocessing/pom.xml +++ b/imageprocessing/pom.xml @@ -8,12 +8,21 @@ imageprocessing 1.0-SNAPSHOT + + 1.3.5 + 1.51h + + net.imagej ij - 1.51h + ${ij.version} + + + org.openimaj + core-image + ${core-image.version} - \ 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)); }