Rename module
This commit is contained in:
28
image-processing/pom.xml
Normal file
28
image-processing/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>imageprocessing</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<core-image.version>1.3.5</core-image.version>
|
||||
<ij.version>1.51h</ij.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.imagej</groupId>
|
||||
<artifactId>ij</artifactId>
|
||||
<version>${ij.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openimaj</groupId>
|
||||
<artifactId>core-image</artifactId>
|
||||
<version>${core-image.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.imageprocessing.imagej;
|
||||
|
||||
import ij.IJ;
|
||||
import ij.ImagePlus;
|
||||
import ij.process.ImageProcessor;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ImageJRectExample {
|
||||
public static void main(String[] args) {
|
||||
ImagePlus imp = IJ.openImage(ImageJRectExample.class.getClassLoader().getResource("lena.jpg").getPath());
|
||||
drawRect(imp);
|
||||
imp.show();
|
||||
}
|
||||
|
||||
private static void drawRect(ImagePlus imp) {
|
||||
ImageProcessor ip = imp.getProcessor();
|
||||
ip.setColor(Color.BLUE);
|
||||
ip.setLineWidth(4);
|
||||
ip.drawRect(10, 10, imp.getWidth() - 20, imp.getHeight() - 20);
|
||||
}
|
||||
}
|
||||
@@ -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[] { 0f, 0f, 255.0f });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.imageprocessing.swing;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SwingRectExample {
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedImage image = loadImage();
|
||||
drawRectangle(image);
|
||||
displayImage(image);
|
||||
}
|
||||
|
||||
private static BufferedImage loadImage() throws IOException {
|
||||
String imagePath = SwingRectExample.class.getClassLoader().getResource("lena.jpg").getPath();
|
||||
return ImageIO.read(new File(imagePath));
|
||||
}
|
||||
|
||||
private static void drawRectangle(BufferedImage image) {
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
g.setStroke(new BasicStroke(3));
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawRect(10, 10, image.getWidth() - 20, image.getHeight() - 20);
|
||||
}
|
||||
|
||||
private static void displayImage(BufferedImage image) {
|
||||
JLabel picLabel = new JLabel(new ImageIcon(image));
|
||||
|
||||
JPanel jPanel = new JPanel();
|
||||
jPanel.add(picLabel);
|
||||
|
||||
JFrame f = new JFrame();
|
||||
f.setSize(new Dimension(image.getWidth(), image.getHeight()));
|
||||
f.add(jPanel);
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
||||
BIN
image-processing/src/main/resources/lena.jpg
Normal file
BIN
image-processing/src/main/resources/lena.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 93 KiB |
Reference in New Issue
Block a user