我有一个来自 1600x1600 图像的矩阵。现在我需要将此矩阵分配到 4x4 块中。举个例子:
00 01 02 03
IMAGE = 04 05 06 07 BLOCK(i) = 00 01 BLOCK(i+1) = 02 03
08 09 0A 0B 04 05 06 07
0C 0D 0E 0F
BLOCK(i+2) = 08 09 BLOCK(i+3) = 0A 0B
0C 0D = 0E 0F
1 ) 首先我不知道图像尺寸,用户打开它。我后来明白了。我的测试图像 1600x1600.但块尺寸固定为 4x4。并且图像尺寸是 ,让我们同意现在可以用 4 分...
2 ) 我不知道会有多少块。
3)我需要稍后访问块的行和coloumb,因为我稍后将对块执行数学运算......例如,与块(n)[x,y]与块(n + 1)的异或运算[x,y]。所以这个decleration部分,这部分程序是非常非常重要的。
我把这部分程序坚持了 2 周,我无法继续。请帮助我。它看起来很简单的代码但是......
我的结构是这样的,开始部分
private void Form1_Load(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap("c:\\yavanna.jpg");
pictureBox1.Image = Image.FromFile("c:\\yavanna.jpg");
int width = bmp.Width;
int height = bmp.Height;
Color p;
int[,] alpha_map_int = new int[width, height];
int[,] red_map_int = new int[width, height];
int[,] green_map_int = new int[width, height];
int[,] blue_map_int = new int[width, height];
int[,] grayscale_map_int = new int[width, height];
string[,] gray_scale_map = new string[width, height];
string temp_hexValue;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
//get pixel value
p = bmp.GetPixel(x, y);
//extract pixel component ARGB
int a = p.A;
alpha_map_int[x, y] = a;
int r = p.R;
red_map_int[x, y] = r;
int g = p.G;
green_map_int[x, y] = g;
int b = p.B;
blue_map_int[x, y] = b;
//convert to gryscale
double grayscale = 0.2126 * red_map_int[x,y] + 0.7152 * green_map_int[x, y] + 0.0722 * blue_map_int[x, y];
grayscale_map_int[x, y] = Convert.ToInt32(grayscale);
temp_hexValue = Convert.ToString(grayscale_map_int[x, y]);
gray_scale_map[x, y] = temp_hexValue;
}
}
牧羊人nacy
MMTTMM
相关分类