图像处理后得到错误的颜色
Getting wrong colors after an image manipulations
我正在尝试对某些值与图像的 RGB 值进行异或,保存该图像并执行后退步骤,以获得原始图像。
问题是,我不知道为什么我的图像不清晰(有一些噪音)。
这是我的代码,下面是一张图片:
Bitmap original = new Bitmap("D:\img\1.jpg");
Bitmap inp_bmp = new Bitmap("D:\img\1.jpg");
int width = inp_bmp.Width;
int height = inp_bmp.Height;
Color pixel;
for (int y = 0; y < height; y += 1)
{
for (int x = 0; x < width; x += 1)
{
pixel = inp_bmp.GetPixel(x, y);
int a = pixel.A;
int r = (pixel.R ^ (1000))%256;
int g = (pixel.G ^ (185675))%256;
int b = (pixel.B ^ (78942))%256;
inp_bmp.SetPixel(x, y, Color.FromArgb(a, r, g, b));
}
}
pictureBox2.Image = inp_bmp;
pictureBox1.Image = original;
inp_bmp.Save("D:\img\4.jpg");
保存图片后,我更改
Bitmap inp_bmp = new Bitmap("D:\img\1.jpg");
对于
Bitmap inp_bmp = new Bitmap("D:\img\4.jpg");
并删除
//inp_bmp.Save("D:\img\4.jpg");
我得到了像
这样的图像
(左为原始,右为结果);
如您所见,我在图 4 中得到了一些错误的颜色,为什么?
总而言之接近原作,但还是不对
我猜你的图片没有使用 8 位颜色。 % 256
假设您有一个 8 位图像。
好的,我找到问题了。问题在于保存图像。
这有帮助:
inp_bmp.Save("D:\img\4.png", System.Drawing.Imaging.ImageFormat.Png);
我正在尝试对某些值与图像的 RGB 值进行异或,保存该图像并执行后退步骤,以获得原始图像。 问题是,我不知道为什么我的图像不清晰(有一些噪音)。 这是我的代码,下面是一张图片:
Bitmap original = new Bitmap("D:\img\1.jpg");
Bitmap inp_bmp = new Bitmap("D:\img\1.jpg");
int width = inp_bmp.Width;
int height = inp_bmp.Height;
Color pixel;
for (int y = 0; y < height; y += 1)
{
for (int x = 0; x < width; x += 1)
{
pixel = inp_bmp.GetPixel(x, y);
int a = pixel.A;
int r = (pixel.R ^ (1000))%256;
int g = (pixel.G ^ (185675))%256;
int b = (pixel.B ^ (78942))%256;
inp_bmp.SetPixel(x, y, Color.FromArgb(a, r, g, b));
}
}
pictureBox2.Image = inp_bmp;
pictureBox1.Image = original;
inp_bmp.Save("D:\img\4.jpg");
保存图片后,我更改
Bitmap inp_bmp = new Bitmap("D:\img\1.jpg");
对于
Bitmap inp_bmp = new Bitmap("D:\img\4.jpg");
并删除
//inp_bmp.Save("D:\img\4.jpg");
我得到了像
这样的图像(左为原始,右为结果); 如您所见,我在图 4 中得到了一些错误的颜色,为什么? 总而言之接近原作,但还是不对
我猜你的图片没有使用 8 位颜色。 % 256
假设您有一个 8 位图像。
好的,我找到问题了。问题在于保存图像。
这有帮助:
inp_bmp.Save("D:\img\4.png", System.Drawing.Imaging.ImageFormat.Png);