如何將640X480影像裡的Pixel統計映射X軸上為直線圖~ |
|
rabbit78585
一般會員 發表:11 回覆:22 積分:6 註冊:2006-08-22 發送簡訊給我 |
http://www.wretch.cc/album/show.php?i=rabbit78585&b=1&f=1412425915&p=0 圖片!
請問如何將二值化後影像640X480~.投射到X軸上如圖C 而將A與B做分割~而留下B部分. 找了站內許多文~不之關鍵字對不對~都沒有相關參考文! 謝謝各位大大 |
CoffeeX
中階會員 發表:18 回覆:121 積分:72 註冊:2005-02-18 發送簡訊給我 |
int *ProjectionX;
ProjectionX = new int[Bmp->Width]; for(int i = 0 ; i < Bmp->Width ; i ) { ProjectionX[i]=0; } for (int i = 0; i < Bmp->Height; i ) { ptr = (Byte*)Bmp->ScanLine[i]; for (int j = 0; j < Bmp->Width; j ) { if( ptr[j] ==0); ProjectionX[j] ; } } delete[] ProjectionX; int MyFunction(int *ProjectionX,Graphics::TBitmap *Bmp,int Low) { int Index; for(int i = 0 ; i < Bmp->Width ; i ) { if( ProjectionX[i] < Low) { Index = i; } } return Index; }
------
=.=??? |
rabbit78585
一般會員 發表:11 回覆:22 積分:6 註冊:2006-08-22 發送簡訊給我 |
謝謝CoffeeX. 參考你程式~也找到相同投影方式的程式!已經把投射X軸寫出來了~那請問投影後..要如何做分割動作! 請再一次指導~謝謝 程式碼: void __fastcall TForm1::FormCreate(TObject *Sender) { Image3->Canvas->Brush->Color = clWhite; Image3->Canvas->FillRect(TRect(0,0,Image3->Width,Image3->Height)); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button6Click(TObject *Sender) { { // 統計水平與垂直方向的投影量 long ProjectV[640] = {0}; long ProjectH[480] = {0}; long Vmax = 0, Hmax = 0; Byte *ptr; for(int row = 0; row < 480; row ) { ptr = (Byte *)Image1->Picture->Bitmap->ScanLine[row]; for(int col = 0; col < 640; col ) { if(ptr[col*3] == 255) // 白點 { ProjectV[col] ; // 垂直方向投影的數量 1 if(ProjectV[col] > Vmax) Vmax = ProjectV[col]; // 統計垂直投影最大 } } } // 畫出垂直方向投影 Image3->Canvas->Pen->Color = clBlack; for(int col = 0; col < 640; col ) { Image3->Canvas->MoveTo(col, Image3->Height); Image3->Canvas->LineTo(col, Image3->Height * (1.0 - (double)ProjectV[col] / (double)Vmax)); } } } <!-- |
-->
harrypp
中階會員 發表:7 回覆:124 積分:61 註冊:2006-08-31 發送簡訊給我 |
--> |
CoffeeX
中階會員 發表:18 回覆:121 積分:72 註冊:2005-02-18 發送簡訊給我 |
寫一個function 先thresh
for(int i = 0; i < Width ; i ) { if( project[i] < thresh ) { project[i] =0; } else { project[i] =1; } } 然後下個部份我用說明的,寫一個丟出起始區塊索引區塊,和結束區塊索引的function 以 vector 作為回傳, 概念上先將 project 複制到一陣列大小為 width 2的動態陣列中,左右兩側補零, 出現 0 1 輸出到起始陣列索引 vector 中, 出現 1 0 輸出到終結陣列索引 vector 中, 這樣就可以完成了 另外要作投影圖可參考使用TChart 蠻方便的
------
=.=??? |
rabbit78585
一般會員 發表:11 回覆:22 積分:6 註冊:2006-08-22 發送簡訊給我 |
===================引 用 文 章=================== 寫一個function 先thresh for(int i = 0; i < Width ; i ) { if( project[i] < thresh ) { project[i] =0; } else { project[i] =1; } } 然後下個部份我用說明的,寫一個丟出起始區塊索引區塊,和結束區塊索引的function 以 vector 作為回傳, 概念上先將 project 複制到一陣列大小為 width 2的動態陣列中,左右兩側補零, 出現 0 1 輸出到起始陣列索引 vector 中, 出現 1 0 輸出到終結陣列索引 vector 中, 這樣就可以完成了 另外要作投影圖可參考使用TChart 蠻方便的 --------------------------------------------------------------------------------------------------------------- 應剛起頭學著寫影像程式~大大是否有範本或範例呢?能讓我參考! 謝謝~ |
CoffeeX
中階會員 發表:18 回覆:121 積分:72 註冊:2005-02-18 發送簡訊給我 |
我尚未測試過你可以作個參考:
//--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- TArray Array; vector vector int *TestArray = new int[5]; for(int i = 0;i < 5;i ) { TestArray[i] = 0; } TestArray[0] = 1; TestArray[1] = 100; TestArray[2] = 200; TestArray[4] = 10; Array.Thresh(5);//TestArray[0] will be 0 vStartIndex = Array.EachEndIndex(); delete[] TestArray; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- class TArray }; //--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- __fastcall TArray::TArray() { Count = 0; } void __fastcall TArray::Thresh(int ThValue) { for(int i = 0;i < Count;i ) { if(Cells[i] > ThValue) { Cells[i] = 0; } else { Cells[i] = 1; } } } vector { vector int *Tmp = new int[Count 2]; for(int i = 1;i < Count 1;i ) { Tmp[i] = Cells[i-1]; } Tmp[0] = 0; Tmp[Count 1] = 0; for(int i = 1;i < Count 1;i ) { if((Tmp[i]==1)&(Tmp[i 1]==0)) { vIndex.push_back(i-1); } } delete[] Tmp; return vIndex; } //--------------------------------------------------------------------------- Vector 部份為 vector < int > 目前網頁顯示似乎有些問題
------
=.=??? |
johnpage
初階會員 發表:0 回覆:79 積分:40 註冊:2004-08-07 發送簡訊給我 |
|
rabbit78585
一般會員 發表:11 回覆:22 積分:6 註冊:2006-08-22 發送簡訊給我 |
===================引 用 文 章=================== 請用類神經作圖形分類 如果要做影像追蹤? 最好別只是取目標物的外框 或許你只是要求物體中心點?? 但在一般情況下 都會誤判??? 有興趣可以參考? 台科大? 電子工程係?? 黃忠偉老師帶的專題 它可以做基礎的幾何圖形追蹤??? 滿好玩的 //--------------------------------------------------------------------------------------------------- 恩~但我圖形都是固定形狀不會改變.做二值化後.投影到X軸上! 因圖形有間隙~想得知間隙在哪個地方 再分割圖形~而把左半部圖形1變0~剩右半部圖形! 請問還有相關程式可參考嗎?~謝謝 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |