![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||
![]() |
||||||||
FOR y = 0 to (HEIGHT - 1)
FOR x = 0 to (WIDTH - 1)
ARRAY2D[ x ][ y ] = ARRAY1D[(WIDTH * y) + x]
END
END
FOR y = 1 to HEIGHT
FOR x = 1 to WIDTH
ARRAY2D[ x ][ y ] = ARRAY1D[(WIDTH * (y - 1)) + x]
END
END
OR
ARRAY2D = reshape(ARRAY1D, WIDTH, HEIGHT);
ARRAY1D = reshape(ARRAY2D, 1, WIDTH * HEIGHT);
where, WIDTH = width of 2D array; HEIGHT = height of 2D array.
int value1 = bImg.getRGB(i,j);
int r1 = (value1 >> 16) & 0xff;
int g1 = (value1 >> 8) & 0xff;
int b1 = (value1 >> 0) & 0xff;
int alpha = 255;
int value = (alpha << 24) | (r << 16) | (g << 8) | b;
Conversion from a 1D array to a 2D array (for MATLAB where indices start from 1)
Similarly, to convert a 2D array into a 1D array you can do:
Extracting r, g, b components from an integer color at (i, j) of a BufferedImage (bImg) in Java
Combining r, g, b components to get a single integer value