Skip to content

Commit ac20dd3

Browse files
author
prd
committed
refactor packages & introduce OpenIMAJ
1 parent 1a17166 commit ac20dd3

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎imageprocessing/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<artifactId>ij</artifactId>
1515
<version>1.51h</version>
1616
</dependency>
17+
<dependency>
18+
<groupId>org.openimaj</groupId>
19+
<artifactId>core-image</artifactId>
20+
<version>1.3.5</version>
21+
</dependency>
1722
</dependencies>
1823

1924
</project>

imageprocessing/src/main/java/imagej/DrawRect.java renamed to imageprocessing/src/main/java/com/baeldung/imageprocessing/imagej/ImageJRectExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package imagej;
1+
package com.baeldung.imageprocessing.imagej;
22

33
import ij.IJ;
44
import ij.ImagePlus;
55
import ij.process.ImageProcessor;
66

77
import java.awt.*;
88

9-
public class DrawRect {
9+
public class ImageJRectExample {
1010
public static void main(String[] args) {
11-
ImagePlus imp = IJ.openImage(DrawRect.class.getClassLoader().getResource("lena.jpg").getPath());
11+
ImagePlus imp = IJ.openImage(ImageJRectExample.class.getClassLoader().getResource("lena.jpg").getPath());
1212
drawRect(imp);
1313
imp.show();
1414
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldung.imageprocessing.openimaj;
2+
3+
import org.openimaj.image.DisplayUtilities;
4+
import org.openimaj.image.ImageUtilities;
5+
import org.openimaj.image.MBFImage;
6+
import org.openimaj.math.geometry.point.Point2d;
7+
import org.openimaj.math.geometry.point.Point2dImpl;
8+
import org.openimaj.math.geometry.shape.Polygon;
9+
10+
import java.io.IOException;
11+
import java.util.Arrays;
12+
13+
public class OpenIMAJRectExample {
14+
public static void main(String[] args) throws IOException {
15+
MBFImage image = ImageUtilities.readMBF(OpenIMAJRectExample.class.getClassLoader().getResource("lena.jpg"));
16+
drawRectangle(image);
17+
DisplayUtilities.display(image);
18+
}
19+
20+
private static void drawRectangle(MBFImage image) {
21+
Point2d tl = new Point2dImpl(10, 10);
22+
Point2d bl = new Point2dImpl(10, image.getHeight()-10);
23+
Point2d br = new Point2dImpl(image.getWidth()-10, image.getHeight()-10);
24+
Point2d tr = new Point2dImpl(image.getWidth() - 10, 10);
25+
Polygon polygon = new Polygon(Arrays.asList(tl, bl, br, tr));
26+
image.drawPolygon(polygon, 4, new Float[] {new Float(0),new Float(0),new Float(255.0)});
27+
}
28+
}

imageprocessing/src/main/java/swing/DrawRect.java renamed to imageprocessing/src/main/java/com/baeldung/imageprocessing/swing/SwingRectExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package swing;
1+
package com.baeldung.imageprocessing.swing;
22

33
import javax.imageio.ImageIO;
44
import javax.swing.*;
@@ -7,15 +7,15 @@
77
import java.io.File;
88
import java.io.IOException;
99

10-
public class DrawRect {
10+
public class SwingRectExample {
1111
public static void main(String[] args) throws IOException {
1212
BufferedImage image = loadImage();
1313
drawRectangle(image);
1414
displayImage(image);
1515
}
1616

1717
private static BufferedImage loadImage() throws IOException {
18-
String imagePath = DrawRect.class.getClassLoader().getResource("lena.jpg").getPath();
18+
String imagePath = SwingRectExample.class.getClassLoader().getResource("lena.jpg").getPath();
1919
return ImageIO.read(new File(imagePath));
2020
}
2121

0 commit comments

Comments
 (0)