作者hsiang915 (嘿嘿嘿)
看板NTUE-CS99
標題[課業]影像處理-BCB版(GRAY+Historgram)
時間Mon Dec 22 09:50:37 2008
物件用到的有Image1、Button1、TChart*1
Image1內嵌大頭照,Button為彩轉灰、顯示Historgram的按鈕,
TChart是統計圖表,由於語言是BCB所以其他版本的C大概只能參考邏輯了,
Button內的程式碼:
void __fastcall TForm1::Button4Click(TObject *Sender)
{
//============統計圖設定=============
int Height,Width,x,y,gray;
Height = Image1->Height; //圖的寬高值是從IMG1物件自己抓取
Width = Image1->Width;
unsigned char grayinfo2[256]={0}; //用以存放灰階值的陣列
Chart2->Legend->Visible=false;//關閉圖例
Chart2->Title->Text->Clear(); //清空標題
Chart2->Title->Text->Add("灰階平均分布");//設定標題
Chart2->LeftAxis->Automatic=false;//不要自動設定 這部分 自己Try一下 就知道在幹嘛囉!!
Chart2->LeftAxis->AutomaticMinimum=false;
Chart2->LeftAxis->AutomaticMaximum=true;
Chart2->LeftAxis->Minimum=0;//設定 從0開始
Chart2->BottomAxis->Automatic=false;
Chart2->BottomAxis->AutomaticMinimum=false;
Chart2->BottomAxis->AutomaticMaximum=false;
Chart2->BottomAxis->Maximum=255;//最大到255
Chart2->BottomAxis->Minimum=0;
Chart2->BottomAxis->Increment=5;//<====間距
for(int clc;clc<256;clc++) //清空統計資訊
{
grayinfo2[clc]=0; //清除存放灰階值的陣列
Series1->Clear(); //清除每一條直方圖
}
Height = Image1->Height; //圖片的寬高值是從IMG1物件
Width = Image1->Width; //自己判斷抓出來的。
{
//-----開始針對每一點作影像轉換RGB to Gray
//用老師上課說的方法RGB除3轉成灰階值
for(y=0;y<Height;y++)
for(x=0;x<Width;x++)
{
int r=GetRValue(Image1->Canvas->Pixels[x][y]); //呼叫WINXP的巨集
int g=GetGValue(Image1->Canvas->Pixels[x][y]);
int b=GetBValue(Image1->Canvas->Pixels[x][y]);
int gray=(r+g+b)/3;
Image1->Canvas->Pixels[x][y]=RGB(gray,gray,gray);
//↑將算完的灰階值存入陣列,原理請參課本P211
grayinfo2[gray]++;
//將灰階值存到對應的值方圖陣列(每次+1)
}
}
//***************下面這段程式在更新 直方圖的數據*********************
for(int k=0;k<256;k++)
{
Series1->Add(grayinfo2[k],"",k);//將每條值方圖的數據從陣列內逐一帶入
}
}
//-----------------------------------
我把程式放在LAB靠近冰箱的那台裡面,如果有需要請自行潛入參考。
告退~----------------------------------------
執行檔下載位置:
http://www.badongo.com/file/12591067
下載完副檔名被改成55的話,請自行改回EXE~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.240.186.117
推 kian3256:酷~!!! 12/22 10:41
推 linjrming:有沒有執行檔可以借來玩玩看啊 12/22 10:47
※ 編輯: hsiang915 來自: 61.64.66.55 (12/22 19:23)
※ 編輯: hsiang915 來自: 61.64.66.55 (12/22 19:25)