Hello high Skilled Programmers
I have a test image 1600x1600. I imported this to a matrix as grayscale int values. Then i created 4x4 sub matrixes from that matrix.I made some math operations in these blocks and created new blocks. Now i need to create a new matrix again (1600x1600) from that new 4x4 blocks.But i couldnt create the loop. I Have (1600/4 * 1600/4 = 160 000) sub matrixes totaly. (Of course my program is not static , the input image can be anything.This is for test image). Now this is my structure.
Bitmap bmp = new Bitmap("c:\\test.jpg");
pictureBox1.Image = Image.FromFile("c:\\test.jpg");
int width = bmp.Width; int height = bmp.Height;
while (y < height) {
while (x < width) {
pxl = bmp.GetPixel(x, y);
int_grayscale_map[x, y] = GetGrayScale(pxl); //getgrayscale is function that returns int value
x++;}
y++;}
int totalblocknumber = (width/4) * (height / 4); //160 000 in this case
Now I created and populated the sub blocks from this codes. Someone helped me here.(think that we puzzled the 1600x1600 image to 4x4 pieces)
Bitmap image = new Bitmap(FILENAME);
List<List<List<Int32>>> grayscale_map_block = newList<List<List<Int32>>>();
for (int row = 0; row < height; row += 4)
{
for (int col = 0; col < width; col += 4)
{
block.Add(new List<List<Color>>() {
new List<Color>() { image.GetPixel(col, row), image.GetPixel(col + 1, row), image.GetPixel(col + 2, row), image.GetPixel(col + 3, row)} ,
new List<Color>() { image.GetPixel(col, row + 1), image.GetPixel(col + 1, row + 1), image.GetPixel(col + 2, row + 1), image.GetPixel(col + 3, row + 1)} ,
new List<Color>() { image.GetPixel(col, row + 2), image.GetPixel(col + 1, row + 2), image.GetPixel(col + 2, row + 2), image.GetPixel(col + 3, row + 2)} ,
new List<Color>() { image.GetPixel(col, row + 3), image.GetPixel(col + 1, row + 3), image.GetPixel(col + 2, row + 3), image.GetPixel(col + 3, row + 3)} ,
});
grayscale_map_block.Add(new List<List<Int32>>() {
new List<Int32>() { GetGrayScale(image.GetPixel(col, row)), GetGrayScale(image.GetPixel(col + 1, row)), GetGrayScale(image.GetPixel(col + 2, row)), GetGrayScale(image.GetPixel(col + 3, row))} ,
new List<Int32>() { GetGrayScale(image.GetPixel(col, row + 1)), GetGrayScale(image.GetPixel(col + 1, row + 1)), GetGrayScale(image.GetPixel(col + 2, row + 1)), GetGrayScale(image.GetPixel(col + 3, row + 1))} ,
new List<Int32>() { GetGrayScale(image.GetPixel(col, row + 2)), GetGrayScale(image.GetPixel(col + 1, row + 2)), GetGrayScale(image.GetPixel(col + 2, row + 2)), GetGrayScale(image.GetPixel(col + 3, row + 2))} ,
new List<Int32>() { GetGrayScale(image.GetPixel(col, row + 3)), GetGrayScale(image.GetPixel(col + 1, row + 3)), GetGrayScale(image.GetPixel(col + 2, row + 3)), GetGrayScale(image.GetPixel(col + 3, row + 3))} ,
});
}
} // Getgrayscale is a function that input color return int value
All that is. Now i have 160 000 piece of 4x4 matrix caled "grayscale_map_block" i am using this code to get the element of the blocks grayscale_map_block [n] [x] [y] / n'th block , x,y element. where n =0-totalblocknumber
From that blocks i must smartly create a loop that get pieces together. A new 1600x1600 matrix. Thanks for your helps..