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

為什麼我做完直方圖等化後,我的圖就不見了~~

尚未結案
Teresa_Chang
一般會員


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

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-04 00:21:23 IP:218.162.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 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 __fastcall TForm1::Button1Click(TObject *Sender) { JpgToBmp(Image1); Byte *ptr; int avg,temp; int Histogram[256]={0}; Graphics::TBitmap *bmp = new Graphics::TBitmap(); Image1->Picture->Bitmap->Assign(bmp); for (int row=0; row < bmp->Height; row ) { ptr = (Byte*) bmp->ScanLine[row]; for (int col=0; col < bmp->Width; col ) { avg = ptr[col]; Histogram[avg]=Histogram[avg] 1; } } for(int i=100;i<120;i ) { Memo1->Lines->Add("low"); Memo1->Lines->Add(i); Memo1->Lines->Add(Histogram[i]); } for(int i=0;i<256;i ) Histogram[i]=(Histogram[i]/(256*256)); for(int i=1;i<256;i ) Histogram[i]=Histogram[i] Histogram[i-1]; for(int i=0;i<256;i ) Histogram[i]=Histogram[i]*255; for (int row=0; row < bmp->Height; row ) { ptr = (Byte*) bmp->ScanLine[row]; for (int col=0; colWidth; col ) { temp=ptr[col]; bmp->Canvas->Pixels[row][col] = int(Histogram [temp]); } } Image1->Picture->Assign(bmp); delete bmp; } 我的原圖是放在Image1中,我想要做直方圖等化後,把Image1重新依直方圖等化後的值重畫,但是Image1不見了,並沒有顯示出來 另外,我利用canvas->LineTo(...,...);的指令想要畫出直方圖等化後的分佈圖,但是為什麼他的圖變成連續性的,不是一個row對映一條值呢? 請問是哪裡出了問題?
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-04 12:02:45 IP:211.76.xxx.xxx 未訂閱
Teresa_Chang 您好:    不精確了解您要的結果,試著回答如下: 程式修改可顯示如下,很難用文字完全說明,您先參考一下。    至於畫成線狀的統計圖,只要修改一下我原先的程式,應該就可以了。

for (int x=1; x<256; x  )
   { canvas->MoveTo(x, (int)(256));
     canvas->LineTo(x, (int)(256-rgb[p][x]*scale));
   }

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  JpgToBmp(Image1);
  toGray2D(Image1);  //先轉成灰階,也可以不轉。
        Byte *ptr;
        int avg,temp;
        //intt Histogram[256]={0};
        float Histogram[256]={0};  // 避免整數相除產生捨去小數的狀況            Graphics::TBitmap *bmp; // = new Graphics::TBitmap();
        //Image1->Picture->Bitmap->Assign(bmp); //Image1的Bitmap會被bmp取代,但bmp未指定內容,所以圖形就不見了。
        bmp = Image1->Picture->Bitmap;            bmp->PixelFormat = pf24bit; // new added
        int skip=1;
        if ( bmp->PixelFormat == pf24bit ) skip = 3;            for (int row=0; row < bmp->Height; row  )
        {
                ptr = (Byte*) bmp->ScanLine[row];
                for (int col=0; col < bmp->Width; col  )
                {
                        avg = ptr[skip*col];
                        Histogram[avg]=Histogram[avg] 1;
                }
        }
        for(int i=100;i<120;i  )
        {
                Memo1->Lines->Add("low");
                Memo1->Lines->Add(i);
                Memo1->Lines->Add(Histogram[i]);
        }            int w = bmp->Width;   // new
        int h = bmp->Height;  // new            for(int i=0;i<256;i  )
                Histogram[i]=(Histogram[i]/(w*h)); //整數型態會導致Histogram[.]通通變零。            for(int i=1;i<256;i  )
                Histogram[i]=Histogram[i] Histogram[i-1];            for(int i=0;i<256;i  )
                Histogram[i]=Histogram[i]*255;            for (int row=0; row < bmp->Height; row  )
        {
                ptr = (Byte*) bmp->ScanLine[row];
                for (int col=0; colWidth; col  )
                {
                        temp=ptr[skip*col];
                        //bmp->Canvas->Pixels[row][col] = (int)(Histogram [temp]);
                        bmp->Canvas->Pixels[col][row] = RGB(Histogram [temp], Histogram [temp], Histogram [temp]);
                }
        }
        //Image1->Picture->Assign(bmp);
        //delete bmp;    }  
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
Teresa_Chang
一般會員


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-11 09:54:50 IP:220.137.xxx.xxx 未訂閱
我已經依照這個方法試了, 可以成功的轉成直方圖等化的圖形, 但是很奇怪的事,我轉完後,再呼叫我原本的畫直方圖的程式, 為什麼做出來的圖會變成離散的那種圖, 為什麼沒有一點連續性呢?
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-12-11 23:17:17 IP:211.76.xxx.xxx 未訂閱
Teresa_Chang 您好: "為什麼做出來的圖會變成離散的那種圖?" 不容易從您的描述中知道問題所在。可能的話把程式上傳,再來測試。 RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
系統時間:2024-05-21 1:18:41
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!