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

請問RGB轉YCRCB問題

答題得分者是:taishyang
jiaching
一般會員


發表:21
回覆:21
積分:8
註冊:2003-07-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-23 03:59:34 IP:211.76.xxx.xxx 未訂閱
我的程式出了一點問題  請各位大大幫我看一下 感激不盡~~~ 這是我的程式碼  
 
void __fastcall TForm1::Button10Click(TObject *Sender)
{
if (img1->Picture->Bitmap->Empty==true)
 ShowMessage("請載入圖檔!!");
 Graphics::TBitmap *Bmp = new Graphics::TBitmap();
 Byte *ptr;
 int r,g,b;
 float y,cr,cb;
 int i,j;
 int threshold;     /*threshold=ScrollBar2->Position;
 Edit2->Text=ScrollBar2->Position;  */
                                     
 Bmp->Assign(img1->Picture->Bitmap);
 for(j=0;jHeight;j  )
 {
  ptr = (Byte *)Bmp->ScanLine[j];
  for(i=0;iWidth;i  )
  {
   b=ptr[i*3];
   g=ptr[i*3 1];
   r=ptr[i*3 2];
   y=0.2989*r  0.5866*g 0.1145*b;
   cr=0.7132*(r-y);
   cb=0.5647*(b-y);
   
/*if((180Picture->Assign(Bmp);
 delete Bmp;    
發表人 - taishyang 於 2003/07/23 23:03:06
taishyang
站務副站長


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-24 20:48:03 IP:140.135.xxx.xxx 未訂閱
jiaching您好:
引言:這一段如果加進去的話 img2的畫面就會全部黑色的而我的目的是希望CR 跟CB值落在一個範圍 比方說綠色 藍色 紅色 青色等等..而且一個顏色的CR跟CB值範圍是未知的 所以需要scrollbar來輔助選取在這裡我不太會用兩個scrollbar去調CR跟CB值 是都onChange嗎?
將程式碼以[ code ]與[ /code ]包起來會比較方便閱讀,我已經幫您改過了 會變成全黑是正常的,因為您的程式就是這樣寫的
 if((180
因為對於單一色階(灰階)來說0(全黑)~255(全白)
您只是給了全黑(0),和全黑 1(1)的色階,看起來當然還是黑色的囉
> class="code"> ScrollBar1->Position-10Position 10 
達到您的目的 順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~ 發表人 -
jiaching
一般會員


發表:21
回覆:21
積分:8
註冊:2003-07-05

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-25 03:35:00 IP:211.76.xxx.xxx 未訂閱
感謝taishyung學長~~~ 我的程式碼改成如下了   其中我用了兩個scrollbar 分別可以設定CR跟CB值 其中threshold1 threshold2 threshold3 threshold4我是用全域變數設定這樣好嗎? 而且使用第一個scrollbar是全白 在用第二個scrollbar就變全黑  請問問題出在哪?   新手上路 請多多指教      第一個scrollbar
 
void __fastcall TForm1::ScrollBar3Change(TObject *Sender)
{
if (img1->Picture->Bitmap->Empty==true)
 ShowMessage("請載入圖檔!!");
 Graphics::TBitmap *Bmp = new Graphics::TBitmap();
 Byte *ptr;
 int r,g,b;
 float y,cr,cb;
 int i,j;
 threshold1=ScrollBar3->Position-20;
 threshold2=ScrollBar3->Position 20;
 Bmp->Assign(img1->Picture->Bitmap);
 for(j=0;jHeight;j  )
 {
  ptr = (Byte *)Bmp->ScanLine[j];
  for(i=0;iWidth;i  )
  {
   b=ptr[i*3];
   g=ptr[i*3 1];
   r=ptr[i*3 2];
   y=0.2989*r  0.5866*g 0.1145*b;
   cr=0.5*r-0.4183*g-0.0817*b;
   cb=0.1688*r-0.3312*g 0.5*b;
   if((threshold1Picture->Assign(Bmp);
 delete Bmp;
第二個scrollbar
if (img1->Picture->Bitmap->Empty==true)
 ShowMessage("請載入圖檔!!");
 Graphics::TBitmap *Bmp = new Graphics::TBitmap();
 Byte *ptr;
 int r,g,b;
 float y,cr,cb;
 int i,j;
 threshold3=ScrollBar1->Position-20;
 threshold4=ScrollBar1->Position 20;
 Bmp->Assign(img1->Picture->Bitmap);
 for(j=0;jHeight;j  )
 {
  ptr = (Byte *)Bmp->ScanLine[j];
  for(i=0;iWidth;i  )
  {
   b=ptr[i*3];
   g=ptr[i*3 1];
   r=ptr[i*3 2];
   y=0.2989*r  0.5866*g 0.1145*b;
   cr=0.7132*(r-y);
   cb=0.5647*(b-y);
   if((threshold1Picture->Assign(Bmp);
 delete Bmp;
發表人 - taishyang 於 2003/07/25 15:05:45
taishyang
站務副站長


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-07-25 15:44:44 IP:140.135.xxx.xxx 未訂閱
jiaching學弟:   1.您的RGB轉YCrCb的公式弄錯了     您要用的應該是     Y = 0.299*R + 0.587*G + 0.114*B     Cb = - 0.1687*R - 0.3313*G + 0.5 *B + 128    Cr = 0.5 *R - 0.4187*G - 0.0813*B + 128   2.判斷式也有問題應該改成
if(cr>threshold1&&crthreshold3&&cb
  最後您要再確認您的ScrollBar->Position範圍是否正確    順心    <>~我也是在學習的階段,回答的不好請您多多見諒與指教~    發表人 - 
        
n38870035
一般會員


發表:2
回覆:14
積分:3
註冊:2003-07-19

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-08-10 15:08:05 IP:140.134.xxx.xxx 未訂閱
我想你的問題應該是尋找膚色吧!你的cb,cr應該先+128在做判斷才對
引言: 感謝taishyung學長~~~ 我的程式碼改成如下了 其中我用了兩個scrollbar 分別可以設定CR跟CB值 其中threshold1 threshold2 threshold3 threshold4我是用全域變數設定這樣好嗎? 而且使用第一個scrollbar是全白 在用第二個scrollbar就變全黑 請問問題出在哪? 新手上路 請多多指教 第一個scrollbar
 
void __fastcall TForm1::ScrollBar3Change(TObject *Sender)
{
if (img1->Picture->Bitmap->Empty==true)
 ShowMessage("請載入圖檔!!");
 Graphics::TBitmap *Bmp = new Graphics::TBitmap();
 Byte *ptr;
 int r,g,b;
 float y,cr,cb;
 int i,j;
 threshold1=ScrollBar3->Position-20;
 threshold2=ScrollBar3->Position 20;
 Bmp->Assign(img1->Picture->Bitmap);
 for(j=0;jHeight;j  )
 {
  ptr = (Byte *)Bmp->ScanLine[j];
  for(i=0;iWidth;i  )
  {
   b=ptr[i*3];
   g=ptr[i*3 1];
   r=ptr[i*3 2];
   y=0.2989*r  0.5866*g 0.1145*b;
   cr=0.5*r-0.4183*g-0.0817*b;
   cb=0.1688*r-0.3312*g 0.5*b;
   if((threshold1Picture->Assign(Bmp);
 delete Bmp;
第二個scrollbar
if (img1->Picture->Bitmap->Empty==true)
 ShowMessage("請載入圖檔!!");
 Graphics::TBitmap *Bmp = new Graphics::TBitmap();
 Byte *ptr;
 int r,g,b;
 float y,cr,cb;
 int i,j;
 threshold3=ScrollBar1->Position-20;
 threshold4=ScrollBar1->Position 20;
 Bmp->Assign(img1->Picture->Bitmap);
 for(j=0;jHeight;j  )
 {
  ptr = (Byte *)Bmp->ScanLine[j];
  for(i=0;iWidth;i  )
  {
   b=ptr[i*3];
   g=ptr[i*3 1];
   r=ptr[i*3 2];
   y=0.2989*r  0.5866*g 0.1145*b;
   cr=0.7132*(r-y);
   cb=0.5647*(b-y);
   if((threshold1Picture->Assign(Bmp);
 delete Bmp;
發表人 - taishyang 於 2003/07/25 15:05:45
系統時間:2024-05-05 12:59:10
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!