[BAEL-3348] Moved code to algorithm-4

This commit is contained in:
dupirefr
2019-11-01 00:35:30 +01:00
parent db85c8f275
commit fee1da6091
20514 changed files with 1642355 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
## Image Processing
This module contains articles about image processing.
### Relevant Articles:
- [Working with Images in Java](https://www.baeldung.com/java-images)
+56
View File
@@ -0,0 +1,56 @@
<?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>
<artifactId>image-processing</artifactId>
<version>1.0-SNAPSHOT</version>
<name>image-processing</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>net.imagej</groupId>
<artifactId>ij</artifactId>
<version>${ij.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.openimaj</groupId>
<artifactId>core-image</artifactId>
<version>${core-image.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-core</artifactId>
<version>${imageio.version}</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-bmp</artifactId>
<version>${imageio.version}</version>
</dependency>
</dependencies>
<properties>
<core-image.version>1.3.5</core-image.version>
<ij.version>1.51h</ij.version>
<imageio.version>3.3.2</imageio.version>
</properties>
</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);
}
}
@@ -0,0 +1,47 @@
package com.baeldung.imageprocessing.twelvemonkeys;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TwelveMonkeysExample {
public static void main(String[] args) throws IOException {
BufferedImage image = loadImage();
drawRectangle(image);
displayImage(image);
}
private static BufferedImage loadImage() throws IOException {
String imagePath = TwelveMonkeysExample.class.getClassLoader().getResource("Penguin.ico").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(200, 200));
f.add(jPanel);
f.setVisible(true);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>