2016-05-22 128 views
-4

可以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

它不會變成黑色和白色。它轉換爲灰度。該術語的網頁搜索將產生信息。 –

+0

@David Heffernan灰度圖像被二進制化爲B/W – MBo

+0

不完全,@Mbo。有*三個*值使用,不只是兩個。 –

回答

1

此代碼使用標準公式將RGB顏色轉換爲在YUV模型中用於電視的強度(灰度)。 Luma coding here

在由PAL和NTSC的REC601亮度(Y')成分中使用的Y'UV和Y'IQ模型被計算爲:Y = 0.299 * R + 0.587 * G + 0.114 * B

我希望其他操作很清晰 - 灰度圖像被二值化 - 淺色(高亮度值)變白,黑色變爲黑色。

-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; 
相關問題