Skip to content

Commit 610433d

Browse files
committed
initial commit
1 parent 0606cb6 commit 610433d

7 files changed

Lines changed: 218 additions & 68 deletions

File tree

image-processing/pom.xml

Lines changed: 93 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,98 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<artifactId>image-processing</artifactId>
6-
<version>1.0-SNAPSHOT</version>
7-
<name>image-processing</name>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>image-processing</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>image-processing</name>
89

9-
<parent>
10-
<groupId>com.baeldung</groupId>
11-
<artifactId>parent-modules</artifactId>
12-
<version>1.0.0-SNAPSHOT</version>
13-
</parent>
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-modules</artifactId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
</parent>
1415

15-
<dependencies>
16-
<dependency>
17-
<groupId>net.imagej</groupId>
18-
<artifactId>ij</artifactId>
19-
<version>${ij.version}</version>
20-
<exclusions>
21-
<exclusion>
22-
<artifactId>commons-logging</artifactId>
23-
<groupId>commons-logging</groupId>
24-
</exclusion>
25-
</exclusions>
26-
</dependency>
27-
<dependency>
28-
<groupId>org.openimaj</groupId>
29-
<artifactId>core-image</artifactId>
30-
<version>${core-image.version}</version>
31-
<exclusions>
32-
<exclusion>
33-
<artifactId>commons-logging</artifactId>
34-
<groupId>commons-logging</groupId>
35-
</exclusion>
36-
</exclusions>
37-
</dependency>
38-
<dependency>
39-
<groupId>org.openpnp</groupId>
40-
<artifactId>opencv</artifactId>
41-
<version>3.4.2-0</version>
42-
</dependency>
43-
<dependency>
44-
<groupId>com.twelvemonkeys.imageio</groupId>
45-
<artifactId>imageio-core</artifactId>
46-
<version>${imageio.version}</version>
47-
</dependency>
48-
<dependency>
49-
<groupId>com.twelvemonkeys.imageio</groupId>
50-
<artifactId>imageio-bmp</artifactId>
51-
<version>${imageio.version}</version>
52-
</dependency>
53-
<dependency>
54-
<groupId>net.sourceforge.tess4j</groupId>
55-
<artifactId>tess4j</artifactId>
56-
<version>${tess4j.version}</version>
57-
</dependency>
58-
<dependency>
59-
<groupId>org.bytedeco</groupId>
60-
<artifactId>tesseract-platform</artifactId>
61-
<version>${tesseract-platform.version}</version>
62-
</dependency>
63-
</dependencies>
64-
65-
<properties>
66-
<core-image.version>1.3.5</core-image.version>
67-
<ij.version>1.51h</ij.version>
68-
<imageio.version>3.3.2</imageio.version>
69-
<tess4j.version>4.5.1</tess4j.version>
70-
<tesseract-platform.version>4.1.0-1.5.2</tesseract-platform.version>
71-
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>net.imagej</groupId>
19+
<artifactId>ij</artifactId>
20+
<version>${ij.version}</version>
21+
<exclusions>
22+
<exclusion>
23+
<artifactId>commons-logging</artifactId>
24+
<groupId>commons-logging</groupId>
25+
</exclusion>
26+
</exclusions>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.openimaj</groupId>
30+
<artifactId>core-image</artifactId>
31+
<version>${core-image.version}</version>
32+
<exclusions>
33+
<exclusion>
34+
<artifactId>commons-logging</artifactId>
35+
<groupId>commons-logging</groupId>
36+
</exclusion>
37+
</exclusions>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.openpnp</groupId>
41+
<artifactId>opencv</artifactId>
42+
<version>3.4.2-0</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.twelvemonkeys.imageio</groupId>
46+
<artifactId>imageio-core</artifactId>
47+
<version>${imageio.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.twelvemonkeys.imageio</groupId>
51+
<artifactId>imageio-bmp</artifactId>
52+
<version>${imageio.version}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>net.sourceforge.tess4j</groupId>
56+
<artifactId>tess4j</artifactId>
57+
<version>${tess4j.version}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.bytedeco</groupId>
61+
<artifactId>tesseract-platform</artifactId>
62+
<version>${tesseract-platform.version}</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.imgscalr</groupId>
66+
<artifactId>imgscalr-lib</artifactId>
67+
<version>${imgscalr-version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>net.coobird</groupId>
71+
<artifactId>thumbnailator</artifactId>
72+
<version>${thumbnailator-version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>com.github.downgoon</groupId>
76+
<artifactId>marvin</artifactId>
77+
<version>${marvin-version}</version>
78+
<type>pom</type>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.github.downgoon</groupId>
82+
<artifactId>MarvinPlugins</artifactId>
83+
<version>${marvin-version}</version>
84+
</dependency>
85+
</dependencies>
86+
87+
<properties>
88+
<core-image.version>1.3.5</core-image.version>
89+
<ij.version>1.51h</ij.version>
90+
<imageio.version>3.3.2</imageio.version>
91+
<tess4j.version>4.5.1</tess4j.version>
92+
<tesseract-platform.version>4.1.0-1.5.2</tesseract-platform.version>
93+
<imgscalr-version>4.2</imgscalr-version>
94+
<thumbnailator-version>0.4.11</thumbnailator-version>
95+
<marvin-version>1.5.5</marvin-version>
96+
</properties>
7297

7398
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.image.resize.core;
2+
3+
import java.awt.Graphics2D;
4+
import java.awt.image.BufferedImage;
5+
import java.io.File;
6+
import java.io.IOException;
7+
8+
import javax.imageio.ImageIO;
9+
10+
public class Graphics2DExample {
11+
12+
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException {
13+
BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
14+
Graphics2D graphics2D = resizedImage.createGraphics();
15+
graphics2D.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null);
16+
graphics2D.dispose();
17+
return resizedImage;
18+
}
19+
20+
public static void main(String[] args) throws IOException {
21+
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
22+
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
23+
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.image.resize.core;
2+
3+
import java.awt.Image;
4+
import java.awt.image.BufferedImage;
5+
import java.io.File;
6+
import java.io.IOException;
7+
8+
import javax.imageio.ImageIO;
9+
10+
public class ImageScaledInstanceExample {
11+
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws IOException {
12+
Image resultingImage = originalImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_DEFAULT);
13+
BufferedImage bufferedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
14+
bufferedImage.getGraphics()
15+
.drawImage(resultingImage, 0, 0, null);
16+
return bufferedImage;
17+
}
18+
19+
public static void main(String[] args) throws IOException {
20+
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
21+
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
22+
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.image.resize.imagescalr;
2+
3+
import java.awt.image.BufferedImage;
4+
import java.io.File;
5+
6+
import javax.imageio.ImageIO;
7+
8+
import org.imgscalr.Scalr;
9+
10+
public class ImagescalrExample {
11+
static BufferedImage simpleResizeImage(BufferedImage originalImage, int targetWidth) throws Exception {
12+
return Scalr.resize(originalImage, targetWidth);
13+
}
14+
15+
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception {
16+
return Scalr.resize(originalImage, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, targetWidth, targetHeight, Scalr.OP_ANTIALIAS);
17+
}
18+
19+
public static void main(String[] args) throws Exception {
20+
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
21+
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
22+
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.image.resize.marvin;
2+
3+
import org.marvinproject.image.transform.scale.Scale;
4+
5+
import marvin.image.MarvinImage;
6+
import marvin.io.MarvinImageIO;
7+
8+
public class MarvinExample {
9+
static void resizeImage(String originalImagePath, int targetWidth, int targetHeight, String outputImagePath) {
10+
MarvinImage image = MarvinImageIO.loadImage(originalImagePath);
11+
Scale scale = new Scale();
12+
scale.load();
13+
scale.setAttribute("newWidth", targetWidth);
14+
scale.setAttribute("newHeight", targetHeight);
15+
scale.process(image.clone(), image, null, null, false);
16+
MarvinImageIO.saveImage(image, outputImagePath);
17+
}
18+
19+
public static void main(String args[]) {
20+
resizeImage("src/main/resources/images/sampleImage.jpg", 200, 200, "src/main/resources/images/sampleImage1.jpg");
21+
}
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.image.resize.thumbnailator;
2+
3+
import java.awt.image.BufferedImage;
4+
import java.io.ByteArrayInputStream;
5+
import java.io.ByteArrayOutputStream;
6+
import java.io.File;
7+
8+
import javax.imageio.ImageIO;
9+
10+
import net.coobird.thumbnailator.Thumbnails;
11+
12+
public class ThumbnailatorExample {
13+
static BufferedImage resizeImage(BufferedImage originalImage, int targetWidth, int targetHeight) throws Exception {
14+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
15+
Thumbnails.of(originalImage)
16+
.size(targetWidth, targetHeight)
17+
.outputFormat("JPEG")
18+
.outputQuality(0.90)
19+
.toOutputStream(outputStream);
20+
byte[] data = outputStream.toByteArray();
21+
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
22+
return ImageIO.read(inputStream);
23+
}
24+
25+
public static void main(String[] args) throws Exception {
26+
BufferedImage originalImage = ImageIO.read(new File("src/main/resources/images/sampleImage.jpg"));
27+
BufferedImage outputImage = resizeImage(originalImage, 200, 200);
28+
ImageIO.write(outputImage, "jpg", new File("src/main/resources/images/sampleImage1.jpg"));
29+
}
30+
}
1.14 MB
Loading

0 commit comments

Comments
 (0)