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

有關影像處理的問題

答題得分者是:taishyang
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-06-05 15:19:16 IP:61.30.xxx.xxx 未訂閱
出處:http://www.chinastu.com/study/html/soft/soft-htm/soft-program/program-luntan/program-2-luntan-010710-04.htm http://delphi.ktop.com.tw/topic.php?TOPIC_ID=21806 各位大大:                    以下是小弟我參考jackkcg大哥所po的文章而          寫出來的一個影像處理的程式,但是在compiler          出現了幾個warning,小弟一直找不到問題所在          能不能請各位大哥提供意見,幫助我解除疑惑 //--------------------------------------------------------------------------- #include  #pragma hdrstop #include "Unit3.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } struct rgb_str{ unsigned char r_color; unsigned char g_color; unsigned char b_color;}; rgb_str rgb[2000][2000]; Graphics::TBitmap *bitmap; int i,j,width,height; int graylevel; TColor color; //--------------------------------------------------------------------------- void __fastcall TForm1::OpenPictureDialog1CanClose(TObject *Sender, bool &CanClose) { { TColor color; width=Image1->Picture->Width; height=Image1->Picture->Height; for(i=1;i<=width;i++) for(j=1;j<=height;j++) { color=Image1->Canvas->Pixels[i][j]; rgb[i][j].r_color=GetRValue(color); rgb[i][j].g_color=GetGValue(color); rgb[i][j].b_color=GetBValue(color); } bitmap=new Graphics::TBitmap; bitmap->Width=width; bitmap->Height=height; }} //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) { Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); }} //--------------------------------------------------------------------------- void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { TColor color=Image1->Canvas->Pixels[X][Y]; Label1->Caption=rgb[i][j].r_color=GetRValue(color); Label2->Caption=rgb[i][j].g_color=GetGValue(color); Label3->Caption=rgb[i][j].b_color=GetBValue(color); Label8->Caption=X; Label9->Caption=Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { int i,j; for(i=1;i<=width;i++){ for(j=1;j<=height;j++){ TColor color=Image1->Canvas->Pixels[i][j]; if (rgb[i][j].g_color=GetGValue(color)<100) Image1->Canvas->Pixels[i][j]=RGB(0,0,0); else Image1->Canvas->Pixels[i][j]=RGB(255,255,255); }}} //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { for (j=1;j<=height;j++) { for (i=1;i<=width;i++) { TColor color=Image1->Canvas->Pixels[i][j]; graylevel=(rgb[i][j].r_color+rgb[i][j].g_color+rgb[i][j].b_color)/3; Image1->Canvas->Pixels[i][j]=RGB(graylevel,graylevel,graylevel); }}} //--------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- Warning: [C++ Warning] Unit3.cpp(74): W8060 Possibly incorrect assignment. [C++ Warning] Unit3.cpp(76): W8018 Assigning unsigned long to TColor. [C++ Warning] Unit3.cpp(80): W8018 Assigning unsigned long to TColor. [C++ Warning] Unit3.cpp(93): W8018 Assigning unsigned long to TColor. [C++ Warning] Unit3.cpp(94): W8004 'color' is assigned a value that is never used. Ece.Winson 上 發表人 - Ece.Winson 於 2003/06/05 15:25:22
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-06-05 15:45:17 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好: 將    
 
  if (rgb[i][j].g_color=GetGValue(color)<100)
  Image1->Canvas->Pixels[i][j]=RGB(0,0,0);
  else
  Image1->Canvas->Pixels[i][j]=RGB(255,255,255);
   
改成
 
   if (rgb[i][j].g_color==GetGValue(color)<100)
     Image1->Canvas->Pixels[i][j]=TColor(RGB(0,0,0));
   else
     Image1->Canvas->Pixels[i][j]=TColor(RGB(255,255,255));
   
順心 <>~我也是在學習的階段,所以請您多多見諒與指教~
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-06-05 15:57:37 IP:61.30.xxx.xxx 未訂閱
taishyang大哥您好: 小弟按照您說的下去改後,還是有出現二個warning如下 不知道是還有哪裡出了問題,是否能夠請您再提供一些意見 [C Warning] Unit3.cpp(74): W8060 Possibly incorrect assignment. [C Warning] Unit3.cpp(94): W8004 'color' is assigned a value that is never used. 謝謝 Ece.Winson上 發表人 - Ece.Winson 於 2003/06/05 15:59:36
JerryKuo
版主


發表:42
回覆:571
積分:322
註冊:2003-03-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-06-05 16:07:05 IP:210.68.xxx.xxx 未訂閱
引言: 出處:http://www.chinastu.com/study/html/soft/soft-htm/soft-program/program-luntan/program-2-luntan-010710-04.htm http://delphi.ktop.com.tw/topic.php?TOPIC_ID=21806 各位大大: 以下是小弟我參考jackkcg大哥所po的文章而 寫出來的一個影像處理的程式,但是在compiler 出現了幾個warning,小弟一直找不到問題所在 能不能請各位大哥提供意見,幫助我解除疑惑 //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit3.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } struct rgb_str{ unsigned char r_color; unsigned char g_color; unsigned char b_color;}; rgb_str rgb[2000][2000]; Graphics::TBitmap *bitmap; int i,j,width,height; int graylevel; TColor color; //--------------------------------------------------------------------------- void __fastcall TForm1::OpenPictureDialog1CanClose(TObject *Sender, bool &CanClose) { { TColor color; width=Image1->Picture->Width; height=Image1->Picture->Height; for(i=1;i<=width;i++) for(j=1;j<=height;j++) { color=Image1->Canvas->Pixels[i][j]; rgb[i][j].r_color=GetRValue(color); rgb[i][j].g_color=GetGValue(color); rgb[i][j].b_color=GetBValue(color); } bitmap=new Graphics::TBitmap; bitmap->Width=width; bitmap->Height=height; }} //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) { Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); }} //--------------------------------------------------------------------------- void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { TColor color=Image1->Canvas->Pixels[X][Y]; Label1->Caption=rgb[i][j].r_color=GetRValue(color); Label2->Caption=rgb[i][j].g_color=GetGValue(color); Label3->Caption=rgb[i][j].b_color=GetBValue(color); Label8->Caption=X; Label9->Caption=Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { int i,j; for(i=1;i<=width;i++){ for(j=1;j<=height;j++){ TColor color=Image1->Canvas->Pixels[i][j]; if (rgb[i][j].g_color=GetGValue(color)<100) Image1->Canvas->Pixels[i][j]=RGB(0,0,0); else Image1->Canvas->Pixels[i][j]=RGB(255,255,255); }}} //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { for (j=1;j<=height;j++) { for (i=1;i<=width;i++) { TColor color=Image1->Canvas->Pixels[i][j]; graylevel=(rgb[i][j].r_color+rgb[i][j].g_color+rgb[i][j].b_color)/3; Image1->Canvas->Pixels[i][j]=RGB(graylevel,graylevel,graylevel); }}} //--------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- Warning: [C++ Warning] Unit3.cpp(74): W8060 Possibly incorrect assignment. [C++ Warning] Unit3.cpp(76): W8018 Assigning unsigned long to TColor. [C++ Warning] Unit3.cpp(80): W8018 Assigning unsigned long to TColor. [C++ Warning] Unit3.cpp(93): W8018 Assigning unsigned long to TColor. [C++ Warning] Unit3.cpp(94): W8004 'color' is assigned a value that is never used. Ece.Winson 上 發表人 - Ece.Winson 於 2003/06/05 15:25:22
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-06-05 16:09:18 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好: 'color' is assigned a value that is never used.   表示您宣告了,但沒使用到   Possibly incorrect assignment.   表示在if 判斷式中的等號要用==而不是用=   不然可能會有incorrect assignment     您不嫌棄的話可以參考我寫的影像處理範例 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=28358 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-06-05 16:36:07 IP:61.30.xxx.xxx 未訂閱
taishyang大哥您好: 非常感謝您的sample,給了小弟學習的機會 但在這裡有幾個疑問想向您請教, 小弟的程式執行的時候在按下gray Button後 有時後出現以下的幾種狀況 A.圖片完全沒有反應,需要再重新load之後才可以work B.圖片執行出的結果並非灰階的情形 c.圖片執行出灰階的情形 ps.同樣的情形也出現在按下binary Button後 希望您能再提供小弟一些意見,謝謝 Ece.Winson 上
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-06-05 16:45:37 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:  
引言: A.圖片完全沒有反應,需要再重新load之後才可以work B.圖片執行出的結果並非灰階的情形 c.圖片執行出灰階的情形 ps.同樣的情形也出現在按下binary Button後
A.的情況我沒發生過耶..BCB5.0 WinXP B.C的情況試試加入 Image1->Picture->Bitmap->PixelFormat=pf24bit; 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-06-05 17:19:45 IP:61.30.xxx.xxx 未訂閱
taishyang大哥您好:                  我用的是BCB4.0的版本WIN ME                  而且我將程式改成如下:    if (Image1->Picture->Bitmap->PixelFormat==pf24bit) graylevel=(rgb[i][j].r_color+rgb[i][j].g_color+rgb[i][j].b_color)/3; Image1->Canvas->Pixels[i][j]=TColor(RGB)(graylevel,graylevel,graylevel));             結果B.C的情形還是存在             下圖是圖片經gray處理後之情形 但是如果出現了A的情形,再load一次之後gray處理後之情形如下圖 便是正常的情況 令我非常困惑不知道大哥是否有過類似的經驗謝謝 Ece.Winson 上
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-06-05 19:06:29 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:   您是讀取與處理過後的圖都在同一個Image上嗎??   如果是的話,我記得有一個function可以解決這樣的現象,不過我現在在打工   晚點再補上function,抱歉< > 順心< > ~我也是在學習的階段,所以請您多多見諒與指教~
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-06-05 19:35:08 IP:140.134.xxx.xxx 未訂閱
taishyang大哥您好: 您的意思是說,上述A.B.C這些情況的發生 是因為我將讀取與處理過後的圖都放在 同一個Image上嗎??如果是這樣的話那真是我 自己太白癡了,不過我也很想知道可以同時將讀取 與處理過後的圖都放在同一個Image上的FUNCTION是 什麼,謝謝您寶貴的意見 Ece.Winson 上
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-06-05 22:47:41 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:    加上 
Image1->Invalidate();
試試 因為我讀圖與秀出處理後的圖是放在不同的Image上,所以不會有您所說的問題 加上上面的function便可以排除在同一個Image上秀圖所產生的問題(您所列舉的) 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-06-07 17:23:33 IP:210.202.xxx.xxx 未訂閱
taishyang大哥您好:                  我參考了你sample中有關scrollbar的寫法後                  但是二值化後之圖形依然不會隨threshold值的變動                  而改變以下是我所寫的程式不知道是不是那裡寫錯了 void __fastcall TForm1::ScrollBar1Change(TObject *Sender) { threshold=ScrollBar1->Position; Edit1->Text=ScrollBar1->Position;    width=Image1->Picture->Width;   height=Image1->Picture->Height;    for(i=1;i<=width;i++) {     for(j=1;j<=height;j++)     {      TColor color=Image1->Canvas->Pixels[i][j];       rgb[i][j].r_color=GetRValue(color);        rgb[i][j].g_color=GetGValue(color);         rgb[i][j].b_color=GetBValue(color); gray=(rgb[i][j].r_color+rgb[i][j].g_color+rgb[i][j].b_color)/3;  if (grayCanvas->Pixels[i][j]=TColor(RGB(0,0,0)); else Image1->Canvas->Pixels[i][j]=TColor(RGB(255,255,255)); }}} 發表人 - Ece.Winson 於 2003/06/07 17:39:45 發表人 - Ece.Winson 於 2003/06/07 17:40:47 發表人 - Ece.Winson 於 2003/06/07 17:54:26
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#13 引用回覆 回覆 發表時間:2003-06-07 17:42:48 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:  
引言: 我參考了你sample中有關scrollbar的寫法後 但是二值化後之圖形依然隨threshold值的變動 而改變
沒錯啊,二值化的圖形隨著scrollbar的不同而有所改變,我不懂您的問題是什麼 而且> > <>~我也是在學習的階段,所以請您多多見諒與指教~
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#14 引用回覆 回覆 發表時間:2003-06-07 17:57:16 IP:210.202.xxx.xxx 未訂閱
taishyang大哥您好: 不好意思我po程式時少了一部份 更正後的程式如下: gray=(rgb[i][j].r_color rgb[i][j].g_color rgb[i][j].b_color)/3; if (gray<threshold) Image1->Canvas->Pixels[i][j]=TColor(RGB(0,0,0)); else Image1->Canvas->Pixels[i][j]=TColor(RGB(255,255,255)); 您說的我都有做了但是還是無法隨scrollbar來變動 發表人 - Ece.Winson 於 2003/06/07 18:01:46 發表人 - Ece.Winson 於 2003/06/07 18:06:06 發表人 - Ece.Winson 於 2003/06/07 18:27:39
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#15 引用回覆 回覆 發表時間:2003-06-07 18:06:06 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:   如圖所示: 按下紅色圈起來的按鈕再把您的程式碼放在裡面即可完整呈現您的程式 大於或小於的符號用[全形]的形式 不過我想您把程式改成
 
gray=(rgb[i][j].r_color+rgb[i][j].g_color+rgb[i][j].b_color)/3;
if (gray >= ScrollBar1->Position)
 Image1->Canvas->Pixels[i][j]=TColor(RGB(0,0,0));
else
 Image1->Canvas->Pixels[i][j]=TColor(RGB(255,255,255));
  
並設定Max為255,Min為0應該就可以了 順心 <>~我也是在學習的階段,所以請您多多見諒與指教~ 發表人 -
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#16 引用回覆 回覆 發表時間:2003-06-07 18:30:14 IP:210.202.xxx.xxx 未訂閱
taishyang大哥您好: 您說的我都有做了但是還是無法隨scrollbar來變動
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#17 引用回覆 回覆 發表時間:2003-06-07 18:45:18 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:  我修改您的程式您試看看,在我的電腦上是可行的WinXP BCB5.0   
struct rgb_str
{
 unsigned char r_color;
 unsigned char g_color;
 unsigned char b_color;
};
rgb_str rgb[2000][2000]; 
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
  int threshold=ScrollBar1->Position;
  Edit1->Text=ScrollBar1->Position;
  int width=Image1->Picture->Width;
  int height=Image1->Picture->Height;
  for(int i=1;i<=width;i++)
  {
   for(int j=1;j<=height;j++)
   {
    TColor color=Image1->Canvas->Pixels[i][j];
    rgb[i][j].r_color=GetRValue(color);
    rgb[i][j].g_color=GetGValue(color);
    rgb[i][j].b_color=GetBValue(color);
    int gray=(rgb[i][j].r_color+rgb[i][j].g_color+rgb[i][j].b_color)/3;
  if (gray >threshold)
    Image1->Canvas->Pixels[i][j]=TColor(RGB(0,0,0));
  else
    Image1->Canvas->Pixels[i][j]=TColor(RGB(255,255,255));
   }
  }
  Image1->Invalidate();
}
  
順心 ~我也是在學習的階段,所以請您多多見諒與指教~
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#18 引用回覆 回覆 發表時間:2003-06-07 20:00:18 IP:210.202.xxx.xxx 未訂閱
taishyang大哥您好: 我照您修改後的程式下去試 結果隨著scrollbar的變動只有 二種圖形在交替變換而已 我使用的也是WinXP BCB5.0 而且我的程式也只能做一次gray及binary的動作 無法像taishyang大哥您的sample中可重覆 gray及binary的動作是我的程式有那裡寫錯了嗎 請大哥指點迷津 發表人 - Ece.Winson 於 2003/06/07 20:07:51
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#19 引用回覆 回覆 發表時間:2003-06-07 20:17:04 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:   您把處理過後的圖秀在另外一個Image上吧   因為在您第一次處理後Image1的內容已經被更改了,所以沒有辦法對原來的圖取不同的臨界值,而是對處理過後的圖再做二值化    
 
if (gray >threshold)
    Image2->Canvas->Pixels[i][j]=TColor(RGB(0,0,0));
  else
    Image2->Canvas->Pixels[i][j]=TColor(RGB(255,255,255));
順心 <>~我也是在學習的階段,所以請您多多見諒與指教~ 發表人 -
Ece.Winson
一般會員


發表:13
回覆:19
積分:6
註冊:2003-05-27

發送簡訊給我
#20 引用回覆 回覆 發表時間:2003-06-07 20:26:32 IP:210.202.xxx.xxx 未訂閱
taishyang大哥您好:                  謝謝您一直不厭其煩的回答我的問題                  解開我的疑惑,謝謝您                  
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#21 引用回覆 回覆 發表時間:2003-06-07 20:36:17 IP:140.135.xxx.xxx 未訂閱
Ece.Winson您好:      能解決您的疑惑最重要囉 >~我也是在學習的階段,所以請您多多見諒與指教~
系統時間:2024-04-27 9:07:06
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!