Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. // int[][][] image = MyImageIO.readImageFromFile("C:\\Users\\Timor\\IdeaProjects\\DorEx\\cat.jpg");
  7. // int[][] theNewImage = rgb2gray(image);
  8. // int[][][] theNewImage2 = rotate90(image);
  9. // MyImageIO.writeImageToFile("C:\\Users\\Timor\\IdeaProjects\\DorEx\\catCopyRotate",theNewImage2);
  10. }
  11.  
  12.  
  13. public static int[][] rgb2gray(int[][][] im) {
  14. int rows = im[0].length;
  15. int coloums = im[0][0].length;
  16. int[][] outImg = new int[rows][coloums];
  17. for (int i = 0; i < rows; ++i) {
  18. for (int j = 0; j < coloums; ++j) {
  19. outImg[i][j] = ((int) (0.3 * im[0][i][j] + 0.59 * im[1][i][j] + 0.11 * im[2][i][j])) * 255;
  20. }
  21. }
  22. return outImg;
  23. }
  24.  
  25. public static int[][][] rotate90(int[][][] im) {
  26. int rows = im[0].length;
  27. int coloums = im[0][0].length;
  28.  
  29. int[][][] outImg = new int[3][coloums][rows]; // 2,0 -> 0,0 1,0 -> 0,1 0,0 -> 0,2
  30. for (int i = 0; i< rows; ++i) {
  31. for (int j = 0 ;j<coloums;++j) {
  32. outImg[0][j][rows-1-i] = im[0][i][j];
  33. outImg[1][j][rows-1-i] = im[1][i][j];
  34. outImg[2][j][rows-1-i] = im[2][i][j];
  35. }
  36. }
  37. return outImg;
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement