【问题标题】:How this code change colored picture into black and white此代码如何将彩色图片变为黑白
【发布时间】:2016-05-22 03:38:37
【问题描述】:

有人能解释一下这段代码是如何将彩色图片变成黑白的吗?

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;

【问题讨论】:

  • 它不会变成黑白的。它转换为灰度。对该词的网络搜索将产生信息。
  • @David Heffernan 灰度图像被二值化为黑白
  • 不完全是,@Mbo。使用了三个值,而不仅仅是两个。
  • @Rob Kennedy 这可能是一个错误
  • 好吧,我看错了

标签: delphi


【解决方案1】:

此代码使用标准公式将 RGB 颜色转换为其强度(灰度),用于为电视开发的 YUV 模型。 Luma coding here

在 PAL 和 NTSC 使用的 Y'UV 和 Y'IQ 模型中,rec601 亮度 (Y') 分量计算为 Y = 0.299 * R + 0.587 * G + 0.114 * B

我希望其他操作清楚 - 灰度图像被二值化 - 浅色(高强度值)变为白色,深色变为黑色。

【讨论】:

    【解决方案2】:
    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;
    

    【讨论】:

      猜你喜欢
      • 2012-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多