Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) {
- // int[][][] image = MyImageIO.readImageFromFile("C:\\Users\\Timor\\IdeaProjects\\DorEx\\cat.jpg");
- // int[][] theNewImage = rgb2gray(image);
- // int[][][] theNewImage2 = rotate90(image);
- // MyImageIO.writeImageToFile("C:\\Users\\Timor\\IdeaProjects\\DorEx\\catCopyRotate",theNewImage2);
- }
- public static int[][] rgb2gray(int[][][] im) {
- int rows = im[0].length;
- int coloums = im[0][0].length;
- int[][] outImg = new int[rows][coloums];
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < coloums; ++j) {
- outImg[i][j] = ((int) (0.3 * im[0][i][j] + 0.59 * im[1][i][j] + 0.11 * im[2][i][j])) * 255;
- }
- }
- return outImg;
- }
- public static int[][][] rotate90(int[][][] im) {
- int rows = im[0].length;
- int coloums = im[0][0].length;
- int[][][] outImg = new int[3][coloums][rows]; // 2,0 -> 0,0 1,0 -> 0,1 0,0 -> 0,2
- for (int i = 0; i< rows; ++i) {
- for (int j = 0 ;j<coloums;++j) {
- outImg[0][j][rows-1-i] = im[0][i][j];
- outImg[1][j][rows-1-i] = im[1][i][j];
- outImg[2][j][rows-1-i] = im[2][i][j];
- }
- }
- return outImg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement