图像信息的参数为指针,怎样对其进行图像处理,比如二值化处理等,

解决方案 »

  1.   

    指向图像数据的地址,我想用scanline操作来获取每行的像素信息,然后进行二值化,结果不行,老报错
      

  2.   

    Image.Buf为这个图像数据的指针地址,我想用下面这段代码进行二值化处理,调试中scanline处有错,怎样才能修正啊,begin        for y := 0 to Image.Height - 1 do
        begin
            p := Image.buf.ScanLine[y];
            for x := 0 to Image.Width - 1 do
            begin  //首先将图像灰度化
                Gray := Round(p[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x
                    * 3] * 0.11);
                if Gray >170 then //按阀值进行二值化
                begin
                    p[x * 3] := 255;
                    p[x * 3 + 1] := 255;
                    p[x * 3 + 2] := 255;
                end
                else
                begin
                    p[x * 3] := 0;
                    p[x * 3 + 1] := 0;
                    p[x * 3 + 2] := 0;
                end;
            end;
        end;
    end;
      

  3.   

    //delphi 7下,测试成功。一开始也是用scanline,怎么都不行,这个逐像素处理,希望对你有帮助。
    var
      x,i,j:integer;
      Gray:int64;
      h,w:integer;
      tc:tcolor;
    begin
      h:=ImgSource.Height;
      w:=ImgSource.Width;  x:=0;
      for i:=0 to h do
      begin
        for j:=0 to w-1   do
        begin
          tc := imgsource.Picture.Bitmap.Canvas.Pixels[j,i];
          gray:=round((getRvalue(tc)*0.3)+(getGvalue(tc)*0.59)+(getBvalue(tc)*0.11));
          if Gray >170 then
          begin
            imgsource.Picture.Bitmap.Canvas.Pixels[j,i]:=TColor($FFFFFF);
          end
          else
          begin
            imgsource.Picture.Bitmap.Canvas.Pixels[j,i]:=TColor($000000);
          end;
          x:=x+3;
        end;
      end;
      

  4.   

    上面的应该为:for i:=0 to h-1 ,不好意思写错了。
      

  5.   

    //delphi 7,测试通过,希望对你有帮助。imgsource为已有图片的timage。
    var
      i,j:integer;
      Gray:int64;
      h,w:integer;
      p:pByteArray;
    begin
      h:=imgsource.Height;
      w:=imgsource.Width;  for i:=0 to h-1 do
      begin
        p:=imgsource.Picture.Bitmap.ScanLine[i];
        for j:=0 to w-1   do
        begin
          gray:=Round((p[j*3+2]*0.3)+(p[j*3+1]*0.59)+(p[j*3]*0.11));
          if Gray >170 then
          begin
            p[j*3]  :=255;
            p[j*3+1]:=255;
            p[j*3+2]:=255;
          end
          else
          begin
            p[j*3]  :=0;
            p[j*3+1]:=0;
            p[j*3+2]:=0;
          end;
        end;
      end;
      self.ImgSource.Refresh;