somebdy可以解释这段代码如何将彩色图片变成黑白图片吗?
Begin
Indeks := 3 * Kolom;
R := PDataBaris[Indeks];
G := PDataBaris[Indeks + 1];
B := PDataBaris[Indeks + 2];
Intensitas := Round(0.2989 * R + 0.5870 * G + 0.1141 * B);
if Intensitas < 128 then
begin
p := p + 1;
Intensitas := 0
end;
if Intensitas > 128 then
begin
h := h + 1;
Intensitas := 255
end;
PDataBaris[Indeks] := Intensitas;
PDataBaris[Indeks + 1] := Intensitas;
PDataBaris[Indeks + 2] := Intensitas;
End;
答案 0 :(得分:1)
此代码使用标准公式将RGB颜色转换为其强度(灰度),用于YUV模型,为电视开发。 Luma coding here
在PAL和NTSC使用的Y'UV和Y'IQ模型中,rec601亮度(Y')分量计算为Y = 0.299 * R + 0.587 * G + 0.114 * B
我希望其他操作清晰 - 灰度图像被二值化 - 浅色(高强度值)变白,暗色变黑。
答案 1 :(得分:-1)
Begin
//there is an array of RGB values of a picture
//every third value is the blue value
Indeks := 3 * Kolom;
R := PDataBaris[Indeks]; //red
G := PDataBaris[Indeks + 1]; //green
B := PDataBaris[Indeks + 2]; //blue
//calulate brightness
//human vision is most sensitive to green and least sensitive to blue
Intensitas := Round(0.2989 * R + 0.5870 * G + 0.1141 * B);
//convert to black/white
//without the added = you'll have 3 values (white, gray, black)
if Intensitas <= 128 then
begin
p := p + 1;
Intensitas := 0
end;
if Intensitas > 128 then
begin
h := h + 1;
Intensitas := 255
end;
//if r=g=b you have a gray value
//based on the code above there are only two (three) values possible:
//black(0) and white(255) (ev. gray (128))
PDataBaris[Indeks] := Intensitas; //red
PDataBaris[Indeks + 1] := Intensitas; //green
PDataBaris[Indeks + 2] := Intensitas; //blue
End;