看板 C_Sharp 關於我們 聯絡資訊
如果用彩色圖形RGB轉成HSI彩色圖形不是看起來會一樣嗎? 可以請各位大大幫忙我看一下CODE嗎? 我哪裡有錯...可以執行 但執行出來的結 果好像是錯的 private void button6_Click(object sender, EventArgs e) { try { Bitmap p6 = (Bitmap)pictureBox2.Image; int h_rgb = p6.Height; int w_rgb = p6.Width; double tempD; double theta; int trans_h; int trans_s; int trans_i; int tempB; for (int i = 0; i < w_rgb; i++) { for (int j = 0; j < h_rgb; j++) { //rgb轉H Color c = p6.GetPixel(i, j); int r = c.R; int g = c.G; int b = c.B; theta = Math.Acos(0.5 * ((r - g) - (r - b)) / Math.Sqrt((r - g) * (r - g) + (r - b) * (g - b))) / (2 * Math.PI); tempD = (b <= g) ? theta : (1 - theta); tempD = (byte)(tempD*255); trans_h = Convert.ToInt32(tempD); //RGB轉S tempB = Math.Min(r, g); tempB = Math.Min(tempB, b); tempD = 1.0 - 3.0 * tempB / (r + g + b); tempD = (byte)(tempD*255); trans_s = Convert.ToInt32(tempD); //RGB轉成I tempD = (r + g + b) / 3; tempD = (byte)(tempD) ; trans_i = Convert.ToInt32(tempD); p6.SetPixel(i, j, Color.FromArgb(trans_h, trans_h, trans_i)); } } //5.傳回 pictureBox2.Image = p6; } catch (Exception ex) { MessageBox.Show(ex.Message); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.25.118.131
leo60037:色彩空間轉換的目的, 不是把轉完的值給bitmap 11/07 00:23
leo60037:而是轉換後, 做一些適合在另一個色彩空間的處理之後 11/07 00:24
leo60037:再轉回rgb給bitmap 11/07 00:24
joetime:感覺用color指令來做點陣圖的像素值擷取會很慢 11/07 23:46
joetime:而且hsi主要是代表此色彩空間亮彩分離的特性 11/07 23:47
joetime:你把hsi的數值直接帶入rgb的點陣圖的像素值當然會錯阿 11/07 23:49
joetime:已經是不同的東西了 11/07 23:52
willy01:喔喔~~大概知道了 我一直以為要把圖再丟回給 bitmap 11/08 21:07