全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1139
推到 Plurk!
推到 Facebook!

一個陣列儲存影像資訊的問題....

答題得分者是:taishyang
harisan3
一般會員


發表:6
回覆:11
積分:3
註冊:2004-12-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-10 14:46:28 IP:218.162.xxx.xxx 未訂閱
我將一個二值化後影像把他儲存到一個陣列裡面,但是陣列裡面的值卻不是255 or 0 ,還有其他值,存到陣列是因為方便我可以做其他處理,但是處理完的結果不正常,然後我去Debug的結果看到陣列內的值並非只有255 or 0...我這樣存會有問題嗎? (影像格式是pf24bit)    
 //以下是我二值化的程式:
 Byte *ptr;
 int r,g,b;
 int gray;
 int i,j;
 int threshold;     MyBmp->Assign(pSrcBitmap);
 for(j=0;jHeight;j  )
 {
  ptr = (Byte *)MyBmp->ScanLine[j];
  for(i=0;iWidth;i  )
  {
   b=ptr[i*3];
   g=ptr[i*3 1];
   r=ptr[i*3 2];
   gray=(r g b)/3;
   if (gray > Threshold)
    gray=255;
   else
    gray=0;
   ptr[i*3]=(Byte)gray;
   ptr[i*3 1]=(Byte)gray;
   ptr[i*3 2]=(Byte)gray;
  }
 }
 pDecBitmap->Assign(MyBmp);    
//我寫成副程式傳處理完的二值化影像去做另一個處理..
Doprocess(Image2->Picture->Bitmap);
//以下是從TImage 將資料存到陣列,問題出在這裡,陣列裡面並非只有255跟0..還有其他值...
void Doprocess(Graphics::TBitmap *pSrcBitmap)
{
  // Allocate memory for image matrix for image processing
  Byte **ImageMatrix = new Byte *[pSrcBitmap->Height];    // STEP 1: SET UP THE ROWS.
  for (int row = 0; row < pSrcBitmap->Height; row  )
  {
   ImageMatrix[row] = new Byte[pSrcBitmap->Width];     // STEP 2: SET UP THE COLUMNS
   ImageMatrix[row]=(Byte *)pSrcBitmap->ScanLine[row];
  }    //以下省略
....
}
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-06-10 15:18:03 IP:210.68.xxx.xxx 未訂閱
您記憶體配置的維度似乎不夠
harisan3
一般會員


發表:6
回覆:11
積分:3
註冊:2004-12-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-06-10 16:33:08 IP:218.162.xxx.xxx 未訂閱
陣列維度應該是夠的 pSrcBitmap->Height * pSrcBitmap->Width
,然後我用Scanline將資料讀進來陣列...我剛剛把ImageMatrix 宣告成Gobal,然後再處理二值化時就把他存進去,結果是可以的,但是不知道為什麼用副程式傳遞就是不行 @@"    [code]
//宣告維度 
Byte **ImageMatrix = new Byte *[pSrcBitmap->Height];    // STEP 1: SET UP THE ROWS.
  for (int row = 0; row < pSrcBitmap->Height; row  )
    ImageMatrix[row] = new Byte[pSrcBitmap->Width];     // STEP 2: SET UP THE COLUMNS    //原來讀資料方式
    ImageMatrix[row]=(Byte *)pSrcBitmap->ScanLine[row];    //改成二值化後直接儲存
   gray=(r g b)/3;
   if (gray > Threshold)
   {
    gray=255;
    ImageMatrix1[j][i]=gray;
   }
   else
   {
    gray=0;
    ImageMatrix1[j][i]=gray;
   }
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-06-10 18:12:26 IP:210.68.xxx.xxx 未訂閱
因為您的圖片是24bit所以應該要配置Height*(Width*3) 不然您ptr的index為何要*3呢? 您的陣列是否有歸0呢? 因為若陣列宣告成global其初始值為0 順心
系統時間:2024-05-02 23:45:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!