delphi 图像处理 二值化


本文整理自网络,侵删。

 
效果图:


var

    p: PByteArray;
    Gray, x, y: Integer;
    Bmp:TBitmap;

begin
Bmp:=TBitmap.Create;
Bmp.Assign(Image1.Picture.Graphic);
    //设置为24位真彩色
    Bmp.PixelFormat := pf24Bit;
    randomize;
    for y := 0 to Bmp.Height - 1 do
    begin
        p := Bmp.scanline[y];
        for x := 0 to Bmp.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 > 128 then //全局阀值128
            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;

    Image1.Picture.Assign(Bmp);

相关阅读 >>

Delphi 从字符串中提取单词、从字符串中提取汉字的函数

Delphi xe6通过wifiapi得到wifi信息

Delphi格式化函数format、formatdatetime和formatfloat

Delphi 关于access的日期类型字段比较的一点认识

Delphi dateof、timeof、yearof、monthof、weekof、dayof、hourof、minuteof、secondof、millisecondof �c 提取时间成分

Delphi tstreamreader 和tstreamwriter

Delphi和c++指针详解

Delphi中自适应窗体的实现

Delphi 2009 之 tstringbuilder 类[1]: create

Delphi 2009 之 tstringbuilder 类[2]: append 与 appendformat

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...