scan line index out of range不知道錯在哪裡。 |
答題得分者是:JerryKuo
|
yangcare
一般會員 發表:7 回覆:6 積分:2 註冊:2004-04-22 發送簡訊給我 |
請各位幫我找找錯﹗我目的是要數出細胞圖中的細胞個數﹐細胞為橢圓形。我的思路是﹕先將原圖二值化﹐圓為白色﹐背景為黑色﹔然後用區域成長法在二值化後的圖中找圓﹔最後在原圖中將圓用方框圈出來。當我用初次編譯時用的圖時﹐程序運行正常﹔但是當我換別的圖時﹐就報錯‘scan line index out of range’﹐我想了很久都找不到錯在哪裡。
下面是我的部份代碼﹕
struct circle { int count; int maxVer; int minVer; int maxHor; int minHor; } cir[200]; //another ﹕code void __fastcall TForm1::Connect(Graphics::TBitmap *pBitmap, int x,int y, struct circle *cir) { BYTE *ptr; cir->count ; ptr = (BYTE*) pBitmap->ScanLine[y]; ptr[x] = 0; if(ptr[x 1]==255) { cir->maxHor = ((x 1) > cir->maxHor) ? (x 1): cir->maxHor; Connect(pBitmap, x 1, y, cir); } ptr = (BYTE*) pBitmap->ScanLine[y 1]; if(ptr[x 1]==255) { cir->maxHor = ((x 1) > cir->maxHor) ? (x 1): cir->maxHor; cir->maxVer = ((y 1) > cir->maxVer) ? (y 1): cir->maxVer; Connect(pBitmap, x 1, y 1, cir); } if(ptr[x]==255) { cir->maxVer = ((y 1) > cir->maxVer) ? (y 1): cir->maxVer; Connect(pBitmap, x, y 1, cir); } if(ptr[x-1]==255) { cir->minHor = ((x-1) < cir->minHor) ? (x-1): cir->minHor; cir->maxVer = ((y 1) > cir->maxVer) ? (y 1): cir->maxVer; Connect(pBitmap, x-1, y 1, cir); } ptr = (BYTE*) pBitmap->ScanLine[y]; if(ptr[x-1]==255) { cir->minHor = ((x-1) < cir->minHor) ? (x-1) : cir->minHor; Connect(pBitmap, x-1, y, cir); } ptr = (BYTE*)pBitmap->ScanLine[y-1]; if(ptr[x-1]==255) { cir->minHor = ((x-1) < cir->minHor) ? (x-1) : cir->minHor; cir->minVer = ((y-1) < cir->minVer) ? (y-1): cir->minVer; Connect(pBitmap, x-1, y-1, cir); } if(ptr[x]==255) { cir->minVer = ((y-1) < cir->minVer) ? (y-1): cir->minVer; Connect(pBitmap, x, y-1, cir); } if(ptr[x 1]==255) { cir->maxHor = ((x 1) > cir->maxHor) ? (x 1): cir->maxHor; cir->minVer = ((y-1) < cir->minVer) ? (y-1): cir->minVer; Connect(pBitmap, x 1, y-1, cir); } } |
JerryKuo
版主 發表:42 回覆:571 積分:322 註冊:2003-03-10 發送簡訊給我 |
引言: 請各位幫我找找錯﹗我目的是要數出細胞圖中的細胞個數﹐細胞為橢圓形。我的思路是﹕先將原圖二值化﹐圓為白色﹐背景為黑色﹔然後用區域成長法在二值化後的圖中找圓﹔最後在原圖中將圓用方框圈出來。當我用初次編譯時用的圖時﹐程序運行正常﹔但是當我換別的圖時﹐就報錯‘scan line index out of range’﹐我想了很久都找不到錯在哪裡。 下面是我的部份代碼﹕yangcare你好: 請問你有考慮到邊界問題嗎? 如果x=0,y=0,x=Width,y=Height 在搜尋時,分別會出現x=-1,y=-1,x=Width 1,y=Height 1。 這幾種情形都會造成scan line index out of range 發表人 - jerrykuo 於 2004/07/09 12:49:18 |
yangcare
一般會員 發表:7 回覆:6 積分:2 註冊:2004-04-22 發送簡訊給我 |
|
JerryKuo
版主 發表:42 回覆:571 積分:322 註冊:2003-03-10 發送簡訊給我 |
引言:你好: 試著帶入y=1的時候,會判斷y=0是否為255,如果是255,則又會判斷一次y-1點, 此時y就out of range。 如果在使用scanline前,判斷y<0或y>Width-1,做為region growing的終止點 ,而x軸的搜尋也應該加上這一道判斷。 發表人 - jerrykuo 於 2004/07/09 15:36:26void __fastcall TForm1::Connect(Graphics::TBitmap *pBitmap, int x,int y, struct circle *cir) { BYTE *ptr; cir->count ; ptr = (BYTE*) pBitmap->ScanLine[y]; ptr[x] = 0; if(ptr[x 1]==255) { cir->maxHor = ((x 1) > cir->maxHor) ? (x 1): cir->maxHor; Connect(pBitmap, x 1, y, cir); } ptr = (BYTE*) pBitmap->ScanLine[y 1]; if(ptr[x 1]==255) { cir->maxHor = ((x 1) > cir->maxHor) ? (x 1): cir->maxHor; cir->maxVer = ((y 1) > cir->maxVer) ? (y 1): cir->maxVer; Connect(pBitmap, x 1, y 1, cir); } if(ptr[x]==255) { cir->maxVer = ((y 1) > cir->maxVer) ? (y 1): cir->maxVer; Connect(pBitmap, x, y 1, cir); } if(ptr[x-1]==255) { cir->minHor = ((x-1) < cir->minHor) ? (x-1): cir->minHor; cir->maxVer = ((y 1) > cir->maxVer) ? (y 1): cir->maxVer; Connect(pBitmap, x-1, y 1, cir); } ptr = (BYTE*) pBitmap->ScanLine[y]; if(ptr[x-1]==255) { cir->minHor = ((x-1) < cir->minHor) ? (x-1) : cir->minHor; Connect(pBitmap, x-1, y, cir); } ptr = (BYTE*)pBitmap->ScanLine[y-1]; if(ptr[x-1]==255) { cir->minHor = ((x-1) < cir->minHor) ? (x-1) : cir->minHor; cir->minVer = ((y-1) < cir->minVer) ? (y-1): cir->minVer; Connect(pBitmap, x-1, y-1, cir); } |
yangcare
一般會員 發表:7 回覆:6 積分:2 註冊:2004-04-22 發送簡訊給我 |
|
yangcare
一般會員 發表:7 回覆:6 積分:2 註冊:2004-04-22 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |