請問求影像灰階值的平均數與變異數要怎麼寫----新手急問 |
答題得分者是:auslk
|
yeh95
一般會員 發表:3 回覆:1 積分:0 註冊:2004-07-09 發送簡訊給我 |
|
auslk
初階會員 發表:35 回覆:77 積分:32 註冊:2003-02-17 發送簡訊給我 |
|
yeh95
一般會員 發表:3 回覆:1 積分:0 註冊:2004-07-09 發送簡訊給我 |
引言: 您好! 這題很簡單喔~您想的太複雜囉! 先定義 *平均數=所有像素值加總/(圖片的長*寬) *變異數=(每一個像素-平均數) (與平均數相差多少數值) 不知道您瞭解囉ㄇ? 剩下就是coding的作業囉(更簡單囉^^) 若要程式,我可以提供給您喔~ (不過最好您要先貼出來讓我看一下) 以上 曾經不會寫程式 小黃狗上 @@~你好.程式能否提供給我呢.我是過很多次都弄不出來.另外要求標準差的話.每個灰階值的各數都要知道.那要怎麼寫呢.我的圖是用256*256.因為剛碰.所以很多都不知道.麻煩您交一下 |
auslk
初階會員 發表:35 回覆:77 積分:32 註冊:2003-02-17 發送簡訊給我 |
您好!
以下程式 給您參考 有三個副程式 一個主程式
首先轉為灰階 存入陣列作處理
定義:
color[0][256]==>B
color[1][256]==>G
color[2][256]==>R
color[3][256]==>Gray
所以只取 color[3][256] 副程式
void image_to_array(TImage * Image1, int *f) { int x, y; int h = Image1->Picture->Height; int w = Image1->Picture->Width; Byte *ptr; for(y = 0; y < h; y ) { ptr = (Byte *) Image1->Picture->Bitmap->ScanLine[y]; for(x = 0; x < w * 3; x = x 3) { f[x 3 * w * y] = (int)ptr[x]; // 將圖片的pixel依序填入 陣列 f[x 1 3 * w * y] = (int)ptr[x 1]; f[x 2 3 * w * y] = (int)ptr[x 2]; } } } //-------矩陣轉到影像------------------------------------------------------ void array_to_image(int *g, TImage * Image2) { int x, y; Byte *ptr; int h = Image2->Picture->Height; int w = Image2->Picture->Width; for(y = 0; y < h; y ) { ptr = (Byte *) Image2->Picture->Bitmap->ScanLine[y]; // 取得圖片第 y // 軸的起始位置 for(x = 0; x < w * 3; x = x 3) { ptr[x 2] = (Byte) g[x 3 * w * y]; // 將陣列的pixel依序填入圖片 ptr[x 1] = (Byte) g[(x 1) 3 * w * y]; ptr[x] = (Byte) g[(x 2) 3 * w * y]; } } } //--------------------------------------------------------------------------- void histo_image(double color[][257], int s_width, int s_height, int *source) { int gray; int x, y, i, j; // color[3] 為灰階 color[2]為紅色 color[1]為綠色 color[0]藍色 // 陣列初始化 for(i = 0; i < 4; i ) for(j = 0; j < 257; j ) color[i][j] = 0; for(y = 0; y < s_height; y ) { for(x = 0; x < s_width * 3; x = x 3) { gray = (source[x 3 * s_width * y] * 28 source[x 3 * s_width * y 1] * 151 source[x 3 * s_width * y 2] * 77) / 256; color[3][gray] ; } } } 主程式 // ========================= int x = Image1->Width; int y = Image1->Height; int i, j,avg1=0,temp; float avg2=0,d=0; int *f = new int[3 * x * y]; double color[4][257]; image_to_array(Image1, f); // 讀取圖片至陣列 histo_image(color, x, y, f); for(i=0,i<256;i ) { avg1=color[3][i] avg1;//總像素值 } avg2=avg1/x*y; // 平均值 for(i=0;i<256;i ) d=color[3][i]-avg2; //變異數 } //===================================== |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |