顯示廣告
隱藏 ✕
看板 Knuckles
作者 Knuckles(阿德)
標題 DIP作業二
時間 2007年11月08日 Thu. PM 03:42:12


計算並產生一張圖的hitogram
	
int x,y;
	
CImage img1; //產生一個CImage物件
	
img1.LoadBmpFile("lena_gray.bmp"); // 載入圖片
	
int height= img1.GetHeight(); // 取得圖檔的高
	
int width = img1.GetWidth();  // 取得圖檔的寬

	
//宣告一個長度為256的int陣列來存histogram
	
int hist[256];
	
//將每個值初始化為0
	
int i;
	
for(i=0;i<256;i++) 
	
	
hist[i] = 0; 
	
//計算histogram
	
for(y=0; y<height; y++)
	
	
for(x=0; x<width; x++)
	
	
	
hist[img1.GetGrayPixel(x,y)] ++;
	
//計算histogram的最大值
	
int hist_max = 0; 
	
for(i=0;i<256;i++)
	
	
if(hist[i] > hist_max)
	
	
	
hist_max = hist[i];

	
//將histogram存成圖檔
	
CImage img1_hist; 
	
int hist_h = 256; //設定histogram圖檔的高
	
img1_hist.Create(256,hist_h,8);
	
for(x=0;x<256;x++)
	
	
for(y=0;y<(hist[x]*((double)hist_h/hist_max));y++)
	
	
	
img1_hist.SetGrayPixel(x,hist_h-y-1,255);
	
img1_hist.SaveBmpFile("lena_hist.bmp");
	
printf("已建立histogram,檔名為lena_hist.bmp\n");
	
printf("hist的最大值為:%d\n",hist_max);
--
※ 來源: 台大電信 DISP 實驗室 (http://disp.twbbs.org)
※ 作者: Knuckles  來自: 140.112.175.130  時間: 2007-11-08 15:42:12
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2009-05-31 15:16:20
※ 編輯: Knuckles  時間: 2010-10-23 04:40:24  來自: 111-248-0-184.dynamic.hinet.net
※ 同主題文章:
● 11-08 15:42 Knuckles □ DIP作業二
  11-10 22:15 Knuckles Re DIP作業二
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 1085 
※ 文章分類: 程式設計 C/C++
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇
看板名稱: 確定(Enter) 取消(Esc) 搜尋(Space)
查詢帳號: 確定(Enter) 取消(Esc) 搜尋(Space)
搜尋: m)m文 b)進板 c)未分類 a)作者 /)標題 q)取消?[q]

搜尋 送出(Enter) 取消(Esc)

回覆文章至: f)看板 m)作者信箱 b)兩者皆是 q)取消?[f]
要引用原文嗎? y)引用原文 n)不引用 a)全部回覆 r)複製原文 q)取消?[y]
轉錄本文章於看板: 1)使用連結 2)使用複製 q)取消 ?[1]
轉寄至站內信箱於使用者: 確定(Enter) 取消(Esc)
轉寄至站內信箱於使用者: 確定(Enter) 取消(Esc)
修改文章標題為: 確定(Enter) 取消(Esc)
修改文章標題為: 確定(Enter) 取消(Esc) 全部(a)

確定要刪除這篇文章?(可按大U救回) 確定(Enter) 取消(Esc)

刪除理由:

確定(Enter) 取消(Esc)
加到這個分類: 確定(Enter) 下一層(→) 回上層(←) 取消(Esc)
你覺得這篇文章: 1)真讚 2)真瞎 q)取消?[1] (再選一次即可收回)
你覺得這篇文章: 1)值得推薦 2)表示反對 3)單純註解 q)取消?[3]
guest
預覽(Enter) 取消(Esc)
上傳圖片
按ctrl+Enter可輸入下一行。
guest
確定要送出? 確定(Enter) 取消(Esc) 繼續(e)
搜尋: 送出(Enter) 取消(Esc)

▏▎▍▌▋▊▉ 請按任意鍵繼續