線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1361
推到 Plurk!
推到 Facebook!

影像比較的問題

答題得分者是:m58610
IORIS
一般會員


發表:15
回覆:21
積分:7
註冊:2005-01-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-28 03:17:20 IP:59.104.xxx.xxx 未訂閱
程式內容是 輸入一張影像先做二值化  與其他影像(已經二值化處理過)去比較 找出最相似的影像    輸入  A圖 與  1圖.2圖.3圖 三張做比較    作法是 取(A.1.2.3)四張圖的pixel值 去做相減 再用泡沫排序法找出piexl值差異最小的    那之後 要怎樣寫才能顯示pixel值差異最小的圖黨呢? 程式碼如下:
  Graphics::TBitmap *Bmp1 = new Graphics::TBitmap();    
  Graphics::TBitmap *Bmp2 = new Graphics::TBitmap();
  Graphics::TBitmap *Bmp3 = new Graphics::TBitmap();
  Graphics::TBitmap *Bmp4 = new Graphics::TBitmap();
  Bmp1->Assign(Image1->Picture->Bitmap);  
  Bmp2->Assign(Image2->Picture->Bitmap);
  Bmp3->Assign(Image3->Picture->Bitmap);
  Bmp4->Assign(Image4->Picture->Bitmap);
  Byte *ptr1,*ptr2,*ptr3,*ptr4;
  int temp[4];
  for(int y=0;yHeight;y  )/*二值化*/
   {
    ptr1=(Byte*)Bmp1->ScanLine[y];
    for(int x=0;xWidth;x  )
     {
      int gray = 0.114*ptr1[3*x] 0.587*ptr1[3*x 1] 0.299*ptr1[3*x 2]; 
      if(gray<127)     
       {gray = 0;}
      else
       {gray = 255;}
      ptr1[3*x]=ptr1[3*x 1]=ptr1[3*x 2]= gray;
     }
   }      for (int i=0;iHeight;i  )/*取值相減*/
   {
    ptr1=(Byte *)Bmp1->ScanLine[i]; 
    ptr2=(Byte *)Bmp2->ScanLine[i];
    ptr3=(Byte *)Bmp3->ScanLine[i];
    ptr4=(Byte *)Bmp4->ScanLine[i];
    for(int j=0;jWidth;j  )     
     {
      temp[1] =abs((int)ptr1[3*j]-(int)ptr2[3*j]);
      temp[2] =abs((int)ptr1[3*j]-(int)ptr3[3*j]);
      temp[3] =abs((int)ptr1[3*j]-(int)ptr4[3*j]);
     }
   }       int tp;   /*泡沫排序*/
   for(int x=0;x<4;x  )
   {
    for(int i=1;i<4;i  )
    {
     if(temp[i 1] < temp[i])
     {
       tp=temp[i];
       temp[i]=temp[i 1];
       temp[i 1]=tp;
     }
    }
   }
   ...............................
   ...................
   /*Image4->Picture->Assign("對應Bmp值");*/            
由於程式最後已重新排列過temp[1]temp[2]temp[3]這矩陣內的值 那要如何才能找到相對應的 Bmp2 or Bmp3 or Bmp4 的值 才能用Image4->Picture->Assign("對應Bmp值"); 這個程式碼來顯示 與A圖最相似的(1or2or3)圖 謝謝!! 還是各位前輩 有其他的寫法 可以提供 麻煩各位前輩來教導了...謝謝!! 發表人 - ioris 於 2005/05/28 03:18:51
m58610
初階會員


發表:22
回覆:83
積分:36
註冊:2003-09-07

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-28 06:16:53 IP:140.118.xxx.xxx 未訂閱
可宣告一個陣列作紀錄 比如說  
 
int record[4] = {0, 1, 2, 3}; 
int tp;   /*泡沫排序*/
   for(int x=0;x<4;x  )
   {
    for(int i=1;i<4;i  )
    {
     if(temp[i 1] < temp[i])
     {
       tp=temp[i];
       temp[i]=temp[i 1];
       temp[i 1]=tp;
       
       //依照temp比較的紀錄來互換record[i]的值
       tp = record[i];
       record[i] = record[i 1];
       record[i 1] = tp;  
       
     }
    }
   }
Image4->Picture->Assign(Bmp[record[0]]);
ps. 請將4個Graphics::TBitmap *Bmp1 = new Graphics::TBitmap();的宣告改成陣列方式比較簡單 ex:
Graphics::TBitmap *Bmp[4]; 
for(int i = 0; i < 4; i  )
   *Bmp[i] = new Graphics::TBitmap(); 
IORIS
一般會員


發表:15
回覆:21
積分:7
註冊:2005-01-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-05-28 12:18:36 IP:210.244.xxx.xxx 未訂閱
多謝m58610 大大又幫我一次忙 我沒想過 Graphics::TBitmap *Bmp1 = new Graphics::TBitmap();的宣告 可以用 陣列來表示 多謝提醒 ^^ 那假設 我要比對的圖 超過3張以上到10幾張的時候 有什麼方法 可以讓比對圖直接載入 不用設10幾個按鈕去開圖... 希望能給我個方向 要找哪方面的書 或資料 謝謝!! (小弟只有基礎的C語言能力...請各位大大見諒!!)
m58610
初階會員


發表:22
回覆:83
積分:36
註冊:2003-09-07

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-05-28 20:01:17 IP:140.118.xxx.xxx 未訂閱
可用AnsiString宣告 假設圖檔名為 aa0.bmp ~ aa9.bmp 比如
AnsiString str;    for(int i = 0; i < 10; i  )
{
    str = "aa"   IntToStr(i)   ".bmp";
    Image4->Picture->LoadFromFile(str);
}
IORIS
一般會員


發表:15
回覆:21
積分:7
註冊:2005-01-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-05-29 01:43:09 IP:59.104.xxx.xxx 未訂閱
多謝m58610大大 又讓我學到一個寫法...for回圈的功能真是多阿.... 謝謝 ^^a
m58610
初階會員


發表:22
回覆:83
積分:36
註冊:2003-09-07

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-05-29 03:37:12 IP:203.70.xxx.xxx 未訂閱
ㄏㄏ 別這樣說 我也都是在這看來的... 沒事就來看看別人的文章.. 到了需要用時才會有方法...
系統時間:2024-04-29 0:56:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!