图形相似性度量和可视化 [英] graphic similarity measure and visualization

查看:81
本文介绍了图形相似性度量和可视化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是S/W开发人员.我的问题是如何比较两个图像并通过比较其像素匹配来可视化输出.我还想显示不匹配的像素区域:confused :: confused:

解决方案

此代码可能对您有所帮助

像这样尝试...

Bitmap img1 = new Bitmap("c:\\rajesh.jpg");
          Bitmap img2 = new Bitmap("c:\\rajesh.jpg");
          Color Myc1; Color Myc2;
          for (int i = 0; i < img1.Height; i++)
              for (int j = 0; j < img2.Width; j++)
              {
                  Myc1 = img1.GetPixel(i, j);
                  Myc2 = img2.GetPixel(i, j);
                  if ((Myc1.R != Myc2.R) || (Myc1.G != Myc2.G) || (Myc1.B != Myc2.B))
                      MessageBox.Show ("Found Mismatch");
              }


制作一个位图的副本-以便您可以在内存中对其进行修改而不会破坏源图像.

在两个位图上都使用LockBits()可以访问原始位图数据.

迭代整个位图数组,并行索引两个图像,比较图像之间的字节.如果字节相同,则将0写入副本;否则,将0写入副本.如果字节不同,则将255写入副本.

现在,您可以查看副本了,只要图像匹配,您就会变黑,而无论它们之间的不同,您都会变白.

您可以写原始值,而不是写255个字节不同的值,但是如果值较低,则很难从黑色的像素匹配"像素中分辨出真实的"黑色像素.

请注意,此操作假定将数组迭代为字节.根据图像的位深度,这可能是不合适的(例如1 bpp图像)或不方便的(例如32 bpp图像,您可以一次处理整个像素,而不是一次处理单个颜色分量).

如果您一次可以处理整个像素,则可能有一种极不可能"的颜色可以用作像素匹配"指示器,而这种颜色不太可能出现在真实图像中.

I am a s/w developer. My question is how to compare two images and visualize the output by comparing its pixel matching. I also want to show the unmatched pixel area :confused::confused:

解决方案

This code may help you

try like this...

Bitmap img1 = new Bitmap("c:\\rajesh.jpg");
          Bitmap img2 = new Bitmap("c:\\rajesh.jpg");
          Color Myc1; Color Myc2;
          for (int i = 0; i < img1.Height; i++)
              for (int j = 0; j < img2.Width; j++)
              {
                  Myc1 = img1.GetPixel(i, j);
                  Myc2 = img2.GetPixel(i, j);
                  if ((Myc1.R != Myc2.R) || (Myc1.G != Myc2.G) || (Myc1.B != Myc2.B))
                      MessageBox.Show ("Found Mismatch");
              }


Make a copy of one of the bitmaps - so that you can modify it (in memory) without destroying your source images.

Use LockBits() on both bitmaps to get access to the raw bitmap data.

Iterate the whole bitmap array, indexing both images in parallel, comparing bytes between images. Where the bytes are the same, write 0 to the copy; where the bytes are different, write 255 to the copy.

Now, you can view the copy, and wherever the images match you''ll get black and wherever they differ you''ll get white.

Instead of writing 255 where bytes differ, you could write the original value - but if it has a low value, it''ll be hard to tell a ''real'' black pixel from a black ''pixels match'' pixel.

Note that this operation assumes iterating the array as bytes. Depending on the bit-depth of the image this may be inappropriate (for example, 1 bpp images) or inconvenient (e.g. 32 bpp images, you could process a whole pixel at a time, instead of a single color component at a time).

If you can process a whole pixel at a time, there might be a ''highly improbably'' color that you could use as the ''pixels match'' indicator, that would be unlikely to occur in a real image.


这篇关于图形相似性度量和可视化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆