[問題] RGB轉HSI
如果用彩色圖形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
→
11/07 00:23, , 1F
11/07 00:23, 1F
→
11/07 00:24, , 2F
11/07 00:24, 2F
→
11/07 00:24, , 3F
11/07 00:24, 3F
→
11/07 23:46, , 4F
11/07 23:46, 4F
→
11/07 23:47, , 5F
11/07 23:47, 5F
→
11/07 23:49, , 6F
11/07 23:49, 6F
→
11/07 23:52, , 7F
11/07 23:52, 7F
→
11/08 21:07, , 8F
11/08 21:07, 8F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章