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

請問pixel排序的問題

尚未結案
wei7278
一般會員


發表:16
回覆:19
積分:12
註冊:2004-09-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-31 11:21:15 IP:61.228.xxx.xxx 未訂閱
譬如原本是p[x][y]=gray ,x,y是座標,p[x][y]是灰階值,我想要把它轉成 a[gray]=座標,array index是灰階值,a[gray]存灰階值為gray的pixel座標 那座標該用什麼資料型態呢? pixel不只一個,所以陣列a應該用二維? 如果用二維,應該需要一個counter去累加,所以在掃pixel前應該先排序?
richtop
資深會員


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-10-31 14:02:56 IP:211.76.xxx.xxx 未訂閱
wei7278 您好:    想像一下將圖形灰階值統計出來,所要做的大概就是您要的吧。 只是在求histogram時,只要算出共有幾個,而您現在要的還要加上是那些點的訊息。 所以比較適合的是利用串列(list)陣列,陣列的索引表示灰階值(0~255),當發現新的點時,加入相對灰階值的串列中;串列元素的內容就是該點的x-y座標。    您先參考看看。
wei7278
一般會員


發表:16
回覆:19
積分:12
註冊:2004-09-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-10-31 16:28:00 IP:220.139.xxx.xxx 未訂閱
不好意思,再請問一下,我大概懂您的意思,不過從來沒用過您說的串列陣列,可以請您指導一下如何用嗎?
richtop
資深會員


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-01 00:16:33 IP:211.76.xxx.xxx 未訂閱
wei7278 您好:    我試著將下列左圖的灰階統計出來,再將統計的結果畫在右圖上。 使用到list,請參考Builder的線上說明及下列連結自行研究了解一下。 < href="http://www.msoe.edu/eecs/cese/resources/stl/list.htm">http://www.msoe.edu/eecs/cese/resources/stl/list.htm。
//---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "UseList0.h"
#include 
using namespace std;    //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------    struct myPoint
{ int x, y;
  myPoint()
  { x=y= 0 ;
  }
  myPoint(int px, int py)
  { x = px;
    y = py;
  }
};    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{ 
}
//---------------------------------------------------------------------------
void toGray(TImage *image)
{ Byte * ptr;
  int 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];
            gray = 0.299*r + 0.587*g + 0.114*b;
            ptr[index  ] = (Byte)gray;
            ptr[index+1] = (Byte)gray;
            ptr[index+2] = (Byte)gray;
            index += 3;
          }
     }
}    //---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
  list gray[256];
  Byte *ptr;
  int value, index;      toGray(Image1);
  Image1->Refresh();
  Image1->Picture->Bitmap->PixelFormat = pf24bit;      for (int y=0; yHeight; y++)
     { ptr = (Byte*) Image1->Picture->Bitmap->ScanLine[y];
       index = 0;
       for (int x=0; xWidth; x++)
          { value = (int)ptr[index];
            gray[value].push_back(myPoint(x,y));
            index += 3;
          }
     }
  ImageResult->AutoSize = true;
  ImageResult->Picture->Bitmap->Width  = Image1->Picture->Width;
  ImageResult->Picture->Bitmap->Height = Image1->Picture->Height;
  ImageResult->Picture->Bitmap->PixelFormat = pf24bit;      int px, py;
  list::const_iterator iter;      for (int k=0; k<256; k++)
     { iter = gray[k].begin();
       for (int p=0; px;
            py = iter->y;
            ImageResult->Picture->Bitmap->Canvas->Pixels[px][py] = (TColor) RGB(k,k,k);
            iter++;
          }
     }
  ImageResult->Refresh();
}
//---------------------------------------------------------------------------
 
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
系統時間:2024-07-01 5:36:16
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!