2010-05-14 75 views
1

任何人都可以在.net中共享代碼或算法(使用模式識別)進行圖像比較。模式識別中的圖像比較.net

我需要比較不同分辨率和紋理的2張圖片,並找出差異。現在我有代碼使用C#

// Load the images. 
Bitmap bm1 = (Bitmap) (Image.FromFile(txtFile1.Text)); 
Bitmap bm2 = (Bitmap) (Image.FromFile(txtFile2.Text)); 

// Make a difference image. 
int wid = Math.Min(bm1.Width, bm2.Width); 
int hgt = Math.Min(bm1.Height, bm2.Height); 
Bitmap bm3 = new Bitmap(wid, hgt); 

// Create the difference image. 
bool are_identical = true; 
int r1; 
int g1; 
int b1; 
int r2; 
int g2; 
int b2; 
int r3; 
int g3; 
int b3; 
Color eq_color = Color.Transparent; 
Color ne_color = Color.Transparent; 
for (int x = 0; x <= wid - 1; x++) 
{ 
    for (int y = 0; y <= hgt - 1; y++) 
    { 
     if (bm1.GetPixel(x, y).Equals(bm2.GetPixel(x, y))) 
     { 
      bm3.SetPixel(x, y, eq_color); 
     } 
     else 
     { 
      bm1.SetPixel(x, y, ne_color); 
      are_identical = false; 
     } 
    } 
} 

// Display the result. 
picResult.Image = bm1; 

    Bitmap Logo = new Bitmap(picResult.Image); 
    Logo.MakeTransparent(Logo.GetPixel(1, 1)); 
    picResult.Image = (Image)Logo; 

//this.Cursor = Cursors.Default; 
if ((bm1.Width != bm2.Width) || (bm1.Height != bm2.Height)) 
{ 
    are_identical = false; 
} 
if (are_identical) 
{ 
    MessageBox.Show("The images are identical"); 
} 
else 
{ 
    MessageBox.Show("The images are different"); 
} 

//bm1.Dispose() 
// bm2.Dispose() 

找到2個圖像之間的差異,但這種比較,如果在2個圖像相同的分辨率和size.if一些陰影是有一個圖像上(但2個圖像是一樣的)它顯示了圖像之間的差異..所以我試圖比較使用模式識別。

+0

當你會發現一個普遍工作的解決方案喊「Hurray」,並製作大型圖像搜索引擎,其他公司仍然在努力做。 – nkrkv 2010-05-14 06:45:10

回答

0

正如nailxx所說,沒有「100%免費工作代碼」之類的東西。幾年前,我幫助實施了「臉部識別」應用程序,我們使用的其中一個是「區域二進制模式」。它不太容易,但它給了相當好的結果。在這裏找到一個關於它的文章: Local binary patterns

編輯:恐怕我找不到最近使用的紙張,它縮短了並固定在LBP本身,而不是如何使用它與紋理。

0

您的要求是一項非常複雜的科學(甚至不是工程)任務。 基本明顯的算法如下:

  1. 不知何故選擇上都比較圖像的所有對象。 這部分相對簡單,可以通過多種方式解決。

  2. 比較所有對象。這部分是科學家的一項任務,考慮到它們可以移動,旋轉,調整大小等等。 :) 但是,這可以解決的情況下,你有固定數量的實體識別。像「圓」,「三角形」,「矩形」,「線」。