線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1485
推到 Plurk!
推到 Facebook!

我想要做一個程式同時擁有顯示直方圖和等化結果兩種功能

尚未結案
Teresa_Chang
一般會員


發表:41
回覆:42
積分:16
註冊:2004-05-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-29 19:55:41 IP:211.74.xxx.xxx 未訂閱
這是我在這個網站中看到的有關直方圖顯示的程式    #include  #pragma hdrstop #include "GetRGBHistogram0.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Form1->DoubleBuffered = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::Exit1Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Load1Click(TObject *Sender) { if ( OpenDialog1->Execute() ) { Image1->Picture->LoadFromFile(OpenDialog1->FileName); Image1->Top = 1; Image1->Left = 1; Graphics::TBitmap *bmp = new Graphics::TBitmap(); bmp->Width = Image1->Picture->Width; bmp->Height = Image1->Picture->Height; bmp->Canvas->Draw(0,0,Image1->Picture->Graphic); Image1->Picture->Bitmap->Assign(bmp); Image1->Refresh(); delete bmp; } } //--------------------------------------------------------------------------- void JpgToBmp(TImage *image) { Graphics::TBitmap *bmp = new Graphics::TBitmap(); bmp->Width = image->Picture->Width; bmp->Height = image->Picture->Height; bmp->Canvas->Draw(0,0,image->Picture->Graphic); image->Picture->Bitmap->Assign(bmp); image->Refresh(); delete bmp; } void showRGBHistogram(TImage *image, TCanvas *canvas) { Byte * ptr; int rgb[3][256]={0}, max[3]={0}, r, g, b, gray, index; image->Picture->Bitmap->PixelFormat = pf24bit; for (int row=0; rowPicture->Height; row ) { ptr = (Byte*) image->Picture->Bitmap->ScanLine[row]; index = 0; for (int col=0; colPicture->Width; col ) { b = ptr[index ]; g = ptr[index 1]; r = ptr[index 2]; rgb[0][b] ; rgb[1][g] ; rgb[2][r] ; index = 3; } } for (int x=0; x<256; x ) { for (int p=0; p<3; p ) { if ( rgb[p][x]>max[p] ) max[p] = rgb[p][x]; } } for (int p=0; p<3; p ){ float scale = (float)256 / max[p]; canvas->MoveTo(0, (int)(256-rgb[p][0]*scale)); for (int x=1; x<256; x ){ canvas->LineTo(x, (int)(256-rgb[p][x]*scale)); } } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { JpgToBmp(Image1); showRGBHistogram(Image1, Image2->Canvas); } 但是我又找了一個有關直方圖等化的程式,但是會發生access 無效的問題, 請問我的問題出在哪呢? 我第一次用bcb寫有關影像處理的問題, 請各位大大多多指教~~ 等化的程式 float gray_ratio1; int gray_level=256; int **gray_value; Byte *ptr; int equalize [2][256]; gray_ratio1 = (float)255/(gray_level-1)/2; for(int i=0; i<2; i ) for(int j=0; j<256; j ) equalize[i][j] = 0; Graphics::TBitmap *bmp4 = new Graphics::TBitmap(); bmp4->Assign(Image2->Picture->Bitmap); for(int i=0; iHeight; i ) { ptr = (Byte*)bmp4->ScanLine[i]; for(int j=0; jWidth ; j ) equalize[0][ ptr[j*3] ] ; } for(int i=0; i<256; i ) { equalize[1][i] = ( (float)equalize[0][i]/(bmp4->Height*bmp4->Width) )*255; if(i != 255) equalize[0][i 1] = equalize[0][i]; } for(int i=0; iHeight; i ) { ptr = (Byte*)bmp4->ScanLine[i]; for(int j=0; j<420; j ) { ptr[j*3] = equalize[1][ ptr[j*3] ]; if(gray_level != 256) { gray_value[i][j] = ( ptr[j*3]/gray_ratio1 1 ) / 2; ptr[j*3] = gray_value[i][j] * 2 * gray_ratio1; } } Image2->Picture->Bitmap->Assign(bmp4); ptr = NULL;
系統時間:2024-05-06 3:25:57
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!