Delphi 图像二值化
本文整理自网络,侵删。
uses
Vcl.Imaging.pngimage, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
Vcl.ExtCtrls, Vcl.ComCtrls;
procedure TForm1.btn_erzhihuaClick(Sender: TObject);
var
p: PByteArray;
Gray, x, y: Integer;
Bmp: TBitmap;
begin
Bmp := TBitmap.Create;
Bmp.Assign(img1.Picture.Bitmap);
//设置为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 > 120 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;
ClearPicNoise(Bmp, 2);
img2.Picture.Bitmap.Assign(Bmp);
Bmp.Free;
end;
来源:http://www.coder163.com/language/delphi/
相关阅读 >>
Delphi 解析json生成json
Delphi 使format输出百分号 %
Delphi 颜色转换成 html 颜色代码
Delphi-改进获取文件md5 hash方法
idftp tencoding and iidtextencoding
Delphi实现百度地图经纬度与地址互转
Delphi 显示简单图形
Delphi流的操作
检测系统信息的单元 computerinfo.pas
Delphi 判断文件名是否有效
更多相关阅读请进入《Delphi》频道 >>
猜你喜欢
联络方式:
400-123-789
邮箱:xiachao@163.com
Q Q:12345678