如何將程式修改至能處理24bit影像檔(取閥值求面積) |
答題得分者是:s8131556
|
b38168
一般會員 發表:3 回覆:0 積分:0 註冊:2008-09-26 發送簡訊給我 |
//---------------------------------------------------------------------------
#include #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; Graphics::TBitmap *TheBitmap, *TempBitmap; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Open1Click(TObject *Sender) { int Height, Width; if(OpenPictureDialog1->Execute()) { Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); } Edit3->Text=Image1->Picture->Bitmap->Height; Edit4->Text=Image1->Picture->Bitmap->Width; } //--------------------------------------------------------------------------- void __fastcall TForm1::Exit1Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::N3x31Click(TObject *Sender) { Byte *ptr, *tptr; int Height, Width, Threshold; Threshold=StrToInt(Edit1->Text); TheBitmap=new Graphics::TBitmap(); TempBitmap=new Graphics::TBitmap(); TheBitmap=Image1->Picture->Bitmap; TempBitmap->Assign(TheBitmap); Height=TheBitmap->Height; Width=TheBitmap->Width; for (int row=1;row ptr=(Byte*) TheBitmap->ScanLine[row]; tptr=(Byte*) TempBitmap->ScanLine[row]; for (int col=1; col if(ptr[col] >Threshold ) tptr[col]=0; else tptr[col]=255; } } Image2->Picture->Bitmap=TempBitmap; } //--------------------------------------------------------------------------- void __fastcall TForm1::Save1Click(TObject *Sender) { if (SavePictureDialog1->Execute()) Image2->Picture->SaveToFile(SavePictureDialog1->FileName); } //--------------------------------------------------------------------------- void __fastcall TForm1::Area1Click(TObject *Sender) { Byte *ptr; int Height, Width, area=0; Height=TempBitmap->Height; Width=TheBitmap->Width; for (int row=1;row ptr=(Byte*) TempBitmap->ScanLine[row]; for (int col=1; col if(ptr[col] == 255 ) area ; } } Edit2->Text=area; } //--------------------------------------------------------------------------- 這支程式只能處理8bit影像檔(我要處理的檔案格式為.bmp),我不知道從哪裡修改,能否幫我看看哪邊需要修改,請賜教。
------
bug 編輯記錄
b38168 重新編輯於 2009-05-03 23:35:14, 註解 無‧
|
s8131556
一般會員 發表:0 回覆:9 積分:16 註冊:2003-10-30 發送簡訊給我 |
請參考 影像處理VI
裡面的ScanLine跟你的差異 例如這個轉成灰階圖的功能: [code cpp] if (Image1->Picture->Bitmap->Empty==true) ShowMessage("請載入圖檔!!"); Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Byte *ptr; int r,g,b; int gray; int i,j; int threshold; Bmp->Assign(Image1->Picture->Bitmap); for(j=0;j { ptr = (Byte *)Bmp->ScanLine[j]; for(i=0;i { //取得顏色值 b=ptr[i*3]; //藍色 g=ptr[i*3 1]; //綠色 r=ptr[i*3 2]; //紅色 gray=0.299*r 0.587*g 0.114*b; //將顏色回存到BMP的每個像素 ptr[i*3]=(Byte)gray; ptr[i*3 1]=(Byte)gray; ptr[i*3 2]=(Byte)gray; } } Image2->Picture->Assign(Bmp); [/code]
編輯記錄
s8131556 重新編輯於 2009-05-08 08:24:59, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |