Java Digital Image Processing: Enverga University

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

SCBC, Life Connect Web-based Church Management System with Predictive Analytics 1

ENVERGA UNIVERSITY

Java
Digital Image Processing

Jubert A. Reyes

July 21, 2019

Submitted in partial fulfillment


of the requirements of
MIT205 Image Processing and Computer
Vision
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 2

ENVERGA UNIVERSITY

Table of Contents

Table of Contents .................................................................................................................. 2


List of Figures ........................................................................................................................ 3
I. GRAYSCALE CONVERSION ....................................................................................... 4
II. GRAYSCALE WITH COLOR ISOLATION ............................................................... 6
III. FLIP HORIZONTAL ................................................................................................. 8
IV. FLIP VERTICAL..................................................................................................... 10
V. ROTATE RIGHT......................................................................................................... 12
VI. ROTATE LEFT ....................................................................................................... 15
........................................................................................................................................... 16
VII. IMAGE SCALING ................................................................................................... 18
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 3

ENVERGA UNIVERSITY

List of Figures

Figure 1 - Grayscale Conversion, boys.jpg

Figure 2 - Grayscale Conversion, Grayscale-boys.jpg

Figure 3 - Grayscale with Color Isolation, sirjoriel.jpg

Figure 4 - Grayscale with Color Isolation, Isolate-sirjoriel.jpg

Figure 5 - Flip Horizontal, jen.jpg

Figure 6 - Flip Horizontal, FlipHoriz-jen.jpg

Figure 7 - Flip Vertical, pool.jpg

Figure 8 - Flip Vertical, FlipVert-pool.jpg

Figure 9 - Rotate Right, guitar.jpg

Figure 10 - Rotate Right, RotateRight-guitar.jpg

Figure 11 - Rotate Left, babyjen.jpg

Figure 12 - Rotate Left, RotateLeft-babyjen.jpg

Figure 13 - Image Scaling, doggie.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 4

ENVERGA UNIVERSITY
I. GRAYSCALE CONVERSION

1. package ImgProcess;
2.
3. import java.awt.*;
4. import java.awt.image.BufferedImage;
5. import java.io.*;
6. import javax.imageio.ImageIO;
7.
8. public class GrayScale {
9.
10. BufferedImage image;
11. int width;
12. int height;
13.
14. public GrayScale() {
15.
16. try {
17. File input = new File("/Users/jubertreyes/Desktop/boys.jpg");
18. image = ImageIO.read(input);
19. width = image.getWidth();
20. height = image.getHeight();
21.
22. for(int i=0; i<height; i++) {
23.
24. for(int j=0; j<width; j++) {
25.
26. Color c = new Color(image.getRGB(j, i));
27. int red = (int)(c.getRed() * 0.299);
28. int green = (int)(c.getGreen() * 0.587);
29. int blue = (int)(c.getBlue() *0.114);
30. Color newColor = new Color(red+green+blue,
31.
32. red+green+blue,red+green+blue);
33.
34. image.setRGB(j,i,newColor.getRGB());
35. }
36. }
37.
38. File ouptut = new File("/Users/jubertreyes/Desktop/Grayscale-boys.jpg");
39. ImageIO.write(image, "jpg", ouptut);
40.
41. } catch (IOException e) {}
42. }
43.
44. static public void main(String args[]) throws Exception {
45. GrayScale obj = new GrayScale();
46. }
47. }
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 5

ENVERGA UNIVERSITY

Figure 1 Grayscale Conversion, boys.jpg

Figure 2. Grayscale Conversion, Grayscale-boys.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 6

ENVERGA UNIVERSITY
II. GRAYSCALE WITH COLOR ISOLATION

1. package ImgProcess;
2.
3. import java.awt.*;
4. import java.awt.image.BufferedImage;
5. import java.io.*;
6. import javax.imageio.ImageIO;
7.
8. public final class RedOnly {
9.
10. BufferedImage image;
11. int width;
12. int height;
13.
14. public RedOnly() {
15.
16. try {
17. File input = new File("/Users/jubertreyes/Desktop/sirjoriel.jpg");
18. image = ImageIO.read(input);
19. width = image.getWidth();
20. height = image.getHeight();
21.
22. for(int i=0; i<height; i++) {
23.
24. for(int j=0; j<width; j++) {
25.
26. Color c = new Color(image.getRGB(j, i));
27. Color newColor;
28.
29. if(isRed(c.getRed(), c.getGreen(), c.getBlue() ))
30. {
31. int red = (int)(c.getRed());
32. int green = (int)(c.getGreen());
33. int blue = (int)(c.getBlue());
34. newColor = new Color(red, green, blue);
35. }
36. else
37. {
38. int red = (int)(c.getRed() * 0.299);
39. int green = (int)(c.getGreen() * 0.587);
40. int blue = (int)(c.getBlue() *0.114);
41. newColor = new Color(red+green+blue,
42. red+green+blue,red+green+blue);
43. }
44.
45. image.setRGB(j,i,newColor.getRGB());
46. }
47. }
48.
49. File ouptut = new File("/Users/jubertreyes/Desktop/Isolate-sirjoriel.jpg");
50. ImageIO.write(image, "jpg", ouptut);
51.
52. } catch (IOException e) {}
53. }
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 7

ENVERGA UNIVERSITY
54.
55. boolean isRed(int r, int g, int b) {
56. return r/3 > g && r/2 > b;
57. }
58.
59. static public void main(String args[]) throws Exception {
60. RedOnly obj = new RedOnly();
61. }
62. }

Figure 4. Grayscale with Color Isolation, sirjoriel.jpg

Figure 3. Grayscale with Color Isolation, Isolate-sirjoriel.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 8

ENVERGA UNIVERSITY

III. FLIP HORIZONTAL

1. package ImgProcess;
2.
3. import java.awt.image.BufferedImage;
4. import java.io.File;
5. import java.io.IOException;
6. import javax.imageio.ImageIO;
7.
8. public class FlipHoriz {
9.
10. BufferedImage image, image2;
11. int width;
12. int height;
13.
14. public FlipHoriz() {
15.
16. try {
17. File input = new File("/Users/jubertreyes/Desktop/jen.jpg");
18. image = ImageIO.read(input);
19. image2 = ImageIO.read(input);
20. width = image.getWidth();
21. height = image.getHeight();
22.
23. for (int i = 0; i < height; i++) {
24.
25. for (int j = 0; j < width; j++) {
26. image2.setRGB(j, i, image.getRGB(image.getWidth() -j-1,i));
27.
28. }
29. }
30.
31. File output = new File("/Users/jubertreyes/Desktop/FlipHoriz-jen.jpg");
32. ImageIO.write(image2, "jpg", output);
33.
34. } catch (IOException e) {
35. }
36.
37. }
38.
39. static public void main(String args[]) throws Exception {
40. FlipHoriz obj = new FlipHoriz();
41. }
42. }
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 9

ENVERGA UNIVERSITY

Figure 6. Flip Horizontal, jen.jpg

Figure 5. Flip Horizontal, FlipHoriz-jen.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 10

ENVERGA UNIVERSITY
IV. FLIP VERTICAL

1. package ImgProcess;
2.
3. import java.awt.image.BufferedImage;
4. import java.io.*;
5. import javax.imageio.ImageIO;
6.
7. public class FlipVert {
8.
9. BufferedImage image, image2;
10. int width;
11. int height;
12.
13. public FlipVert() {
14.
15. try {
16. File input = new File("/Users/jubertreyes/Desktop/pool.jpg");
17. image = ImageIO.read(input);
18. image2 = ImageIO.read(input);
19. width = image.getWidth();
20. height = image.getHeight();
21.
22. for(int i=0; i<height; i++) {
23.
24. for(int j=0; j<width; j++) {
25.
26. image2.setRGB(j, (height - 1) - i, image.getRGB(j, i));
27. }
28. }
29.
30. File ouptut = new File("/Users/jubertreyes/Desktop/FlipVert-pool.jpg");
31. ImageIO.write(image2, "jpg", ouptut);
32.
33. } catch (IOException e) {}
34. }
35.
36. static public void main(String args[]) throws Exception {
37. FlipVert obj = new FlipVert();
38. }
39. }
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 11

ENVERGA UNIVERSITY

Figure 8. Flip Vertical, pool.jpg

Figure 7. Flip Vertical, FlipVert-pool.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 12

ENVERGA UNIVERSITY
V. ROTATE RIGHT

1. package ImgProcess;
2.
3. import java.awt.image.BufferedImage;
4. import java.io.*;
5. import javax.imageio.ImageIO;
6.
7. public class RotateRight {
8.
9. BufferedImage image;
10. int width;
11. int height;
12.
13. public RotateRight() {
14.
15. try {
16. File input = new File("/Users/jubertreyes/Desktop/guitar.jpg");
17. image = ImageIO.read(input);
18. // image2 = ImageIO.read(input);
19. width = image.getWidth();
20. height = image.getHeight();
21. BufferedImage image2 = new BufferedImage(height, width, image.getType());
22. for(int y=0; y<height; y++) {
23.
24. for(int x=0; x<width; x++) {
25.
26. image2.setRGB((height-1)-y, x, image.getRGB(x, y));
27. }
28. }
29.
30. File ouptut = new File("/Users/jubertreyes/Desktop/RotateRight-guitar.jpg");
31. ImageIO.write(image2, "jpg", ouptut);
32.
33. } catch (IOException e) {}
34. }
35.
36. static public void main(String args[]) throws Exception {
37. RotateRight obj = new RotateRight();
38. }
39. }
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 13

ENVERGA UNIVERSITY

Figure 9. Rotate Right, guitar.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 14

ENVERGA UNIVERSITY

Figure 10. Rotate Right, RotateRight-guitar.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 15

ENVERGA UNIVERSITY
VI. ROTATE LEFT

1. package ImgProcess;
2.
3. import java.awt.image.BufferedImage;
4. import java.io.*;
5. import javax.imageio.ImageIO;
6.
7. public class RotateLeft {
8.
9. BufferedImage image;
10. int width;
11. int height;
12.
13. public RotateLeft() {
14.
15. try {
16. File input = new File("/Users/jubertreyes/Desktop/babyjen.jpg");
17. image = ImageIO.read(input);
18. width = image.getWidth();
19. height = image.getHeight();
20.
21. BufferedImage image2 = new BufferedImage(height, width, image.getType());
22. for(int y=0; y<height; y++) {
23.
24. for(int x=0; x<width; x++) {
25. image2.setRGB(y, (width - 1) - x, image.getRGB(x, y));
26. }
27. }
28.
29. File ouptut = new File("/Users/jubertreyes/Desktop/RotateLeft-babyjen.jpg");
30. ImageIO.write(image2, "jpg", ouptut);
31.
32. } catch (IOException e) {}
33. }
34.
35. static public void main(String args[]) throws Exception {
36. RotateLeft obj = new RotateLeft();
37. }
38. }
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 16

ENVERGA UNIVERSITY

Figure 11. Rotate Left, babyjen.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 17

ENVERGA UNIVERSITY

Figure 12. Rotate Left, RotateLeft-babyjen.jpg


SCBC, Life Connect Web-based Church Management System with Predictive Analytics 18

ENVERGA UNIVERSITY
VII. IMAGE SCALING

1. package ImgProcess;
2.
3. import java.awt.image.BufferedImage;
4. import java.io.*;
5. import javax.imageio.ImageIO;
6.
7. public class ReSize {
8.
9. BufferedImage image;
10. int width;
11. int height;
12. int i =2;
13. public ReSize() {
14.
15. try {
16. File input = new File("/Users/jubertreyes/Desktop/doggie.jpg");
17. image = ImageIO.read(input);
18. width = image.getWidth();
19. height = image.getHeight();
20.
21. BufferedImage image2 = new BufferedImage(height, width, image.getType());
22.
23. for(int y=0; y<height; y++) {
24.
25. for(int x=0; x<width; x++) {
26.
27. image2.setRGB(x, y, image2.getRGB(x, y));
28. }
29. }
30. File ouptut = new File("/Users/jubertreyes/Desktop/ReSize-doggie.jpg");
31. ImageIO.write(image2, "jpg", ouptut);
32.
33. } catch (IOException e) {}
34. }
35. static public void main(String args[]) throws Exception {
36. ReSize obj = new ReSize();
37. }
38. }
SCBC, Life Connect Web-based Church Management System with Predictive Analytics 19

ENVERGA UNIVERSITY

Figure 13. Image Scaling, doggie.jpg

You might also like