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

影像標籤化的問題,還有如何做pixel的選取

尚未結案
tom071912
一般會員


發表:2
回覆:2
積分:0
註冊:2010-05-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-05-12 00:46:47 IP:124.9.xxx.xxx 訂閱
各位高手前被你好~~

這是我的標籤化程式

各位高手前被你好~~

這是我的標籤化程式

void __fastcall TForm1::N10Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap,*TempBitmap ; //宣告兩張圖 THEBITMAP和TEMPBITMAP
TempBitmap=new Graphics::TBitmap;
TheBitmap=Image1->Picture->Bitmap; //宣告
TheBitmap->PixelFormat=pf24bit;
TempBitmap->Assign(TheBitmap);
Byte *ptr1,*ptr2,*ptr3,*ptr4;
int **a,label=0,area1=0,sum=0;
//a是影像標記後存放的矩陣
a=new int*[TheBitmap->Height];
for(int i=0;iHeight;i )
a[i]=new int[TheBitmap->Width];
for(int i=0;iHeight;i )
{
for(int j=0;jWidth;j )
a[i][j]=0;
}
//第一次標記
for(int y=0;yHeight;y )
{
ptr1=(Byte*)TheBitmap->ScanLine[y];
//ptr2=(Byte*)TempBitmap->ScanLine[y];
for(int x=0;xWidth;x )
{
if (ptr1[x*3]==0) a[y][x]=label ;
else a[y][x]=999999999;
}
}
for(int i=0;i<100;i )
{
//由左而右、由上而下標記
for(int y=1;yHeight-1;y )
{
ptr1=(Byte*)TheBitmap->ScanLine[y];
ptr2=(Byte*)TempBitmap->ScanLine[y];
for(int x=1;xWidth-1;x )
{
if(a[y][x]!=999999999)
{
int b[9]={0,0,0,0,0,0,0,0,0};
int t,i,j,num=9;
b[0]=a[y-1][x-1];
b[1]=a[y-1][x];
b[2]=a[y-1][x 1];
b[3]=a[y][x-1];
b[4]=a[y][x];
b[5]=a[y][x 1];
b[6]=a[y 1][x-1];
b[7]=a[y 1][x];
b[8]=a[y 1][x 1];
for(i=num-2;i>=0;i--)
for(j=0;j<=i;j )
if(b[j]>b[j 1])
{
t=b[j];
b[j]=b[j 1];
b[j 1]=t;
}
a[y][x]=b[0];
}
}
}
}
///計算a矩陣標記值的個數
int *temp;
temp=new int[label] ;
for (int n=0;n
temp[n]=0;
for(int y=0;yHeight;y )
{
ptr1=(Byte*)TheBitmap->ScanLine[y] ;
for (int x=0;xWidth;x )
{
if (a[y][x]!=999999999 )
temp[a[y][x]] ;
}
}
//指定pixel門檻
for(int n=0;n
{
if(temp[n]!=0)
if(temp[n]>=sum)
{
sum=temp[n];
area1=n;
}
}
for(int y=0;yHeight;y )
{
ptr1=(Byte*)TheBitmap->ScanLine[y];
ptr2=(Byte*)TempBitmap->ScanLine[y];
for(int x=0;xWidth;x )
{
if(a[y][x]!=area1)
{
ptr2[x*3]=255;
ptr2[x*3 1]=255;
ptr2[x*3 2]=255;
}
else
{
ptr2[x*3]=0;
ptr2[x*3 1]=0;
ptr2[x*3 2]=0;
}
}
}
Image2->Picture->Bitmap=TempBitmap;
delete TempBitmap;
delete []a;
}



但結果並不是我想要的

此程式裡標出是從小排到大,但我想要的是一區塊都是標為1,另一區塊標為2,再另一區塊標為3,以此類推

這樣該如何修改呢

還有

標完後如何做pixel的選取

例如:大於5000pixel的像素不要

麻煩各位高手了
編輯記錄
tom071912 重新編輯於 2010-05-12 00:48:38, 註解 無‧
tom071912 重新編輯於 2010-05-12 00:49:12, 註解 無‧
istillloving
高階會員


發表:33
回覆:182
積分:183
註冊:2008-10-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-05-13 12:24:06 IP:140.127.xxx.xxx 訂閱
請問

在你的影像中

哪些條件需要被標籤

哪些條件不需要被標籤
------
恩...
tom071912
一般會員


發表:2
回覆:2
積分:0
註冊:2010-05-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-05-18 18:09:16 IP:140.118.xxx.xxx 訂閱
經過二值化後,我要標的是黑色區域
istillloving
高階會員


發表:33
回覆:182
積分:183
註冊:2008-10-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-05-18 20:24:03 IP:124.9.xxx.xxx 訂閱
你好:

我之前的作法是設一個旗標 fleg 先初始為1

假設原始影像是用buff 陣列存 而另一個是旗標陣列把它稱作bufffleg

buff 和 bufffleg 兩個陣列大小相同

而bufffleg初始化為0

然後對 buff 做掃描

遇到我想要像素點我就把旗標累加 累加之前在bufffleg填入fleg標籤值

整個掃描完之後 bufffleg 就是ㄧ個標籤後的陣列了

然後你就可以對這個陣列做處理 相鄰沒有間隔的標籤就把兩個不ㄧ樣的標籤選擇一個當作共同的標籤

我是用while迴圈 ㄧ值跑 跑到不能合併為止

但是這方法說真的有點慢 雖然是很容易寫沒錯



===================引 用 tom071912 文 章===================
經過二值化後,我要標的是黑色區域
------
恩...
系統時間:2024-04-26 4:13:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!