文章目录
图像的代数与图像分割
提示:这里可以添加技术概要
核心源码
{------------------------------------
By SQLserver and huazai
--------------------------------- }
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, StdCtrls, ExtCtrls, math;
type
TMyPicture = class(TForm)
Image1: TImage;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
Button1: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure PictureTwoValue(Bitmap: TBitmap);
function Xihua(Bitmap: TBitmap): Boolean;
procedure HorizonProjection(Bitmap: TBitmap; Horic: Boolean);
procedure Convolve(ray: array of integer; z: word; aBmp: TBitmap);
procedure CopyMe(Tobmp: TBitmap; Frombmp: TBitmap);
function BitmapErose(Bitmap: TBitmap; Horic: Boolean): Boolean;
function BitmapDilate(Bitmap: TBitmap; Hori: Boolean): Boolean;
{ Private declarations }
public
{ Public declarations }
end;
type
TRGBArray = array[0…32767] of TRGBTriple;
PRGBArray = ^TRGBArray;
var
MyPicture: TMyPicture;
backbmp: Tbitmap;
implementation
{$R *.dfm}
function TMyPicture.BitmapDilate(Bitmap: TBitmap; Hori: Boolean): Boolean;
var
X, Y: integer;
O, P, Q, R: pByteArray;
newbmp: TBitmap;
begin
newbmp := TBitmap.Create;
newbmp.Assign(bitmap);
Hori := True;
if (Hori) then
begin
for Y := 1 to newbmp.Height - 2 do
begin
O := bitmap.ScanLine[Y];
P := newbmp.ScanLine[Y - 1];
Q := newbmp.ScanLine[Y];
R := newbmp.ScanLine[Y + 1];
for X := 1 to newbmp.Width - 2 do
begin
if ((O[3 * X] = 255) and (O[3 * X + 1] = 255) and (O[3 * X
+ 2] = 255)) then
begin
if (((Q[3 * (X - 1)] = 0) and (Q[3 * (X - 1) + 1] = 0)
and (Q[3 * (X - 1) + 2] = 0)) or ((Q[3 * (X + 1)]
= 0)
and (Q[3 * (X + 1) + 1] = 0) and
(Q[3 * (X + 1) + 2] = 0)) or ((P[3 * X] = 0) and
(P[3 * X + 1] = 0) and (P[3 * X + 2] = 0))
or ((R[3 * X] = 0) and (R[3 * X + 1] = 0) and
(R[3 * X + 2] = 0))) then
begin
O[3 * X] := 0;
O[3 * X + 1] := 0;
O[3 * X + 2] := 0;
end;
end;
end;
end;
end
else
for Y := 1 to newbmp.Height - 2 do
begin
O := bitmap.ScanLine[Y];
Q := newbmp.ScanLine[Y];
for X := 1 to newbmp.Width - 2 do
begin
if ((O[3 * X] = 255) and (O[3 * X + 1] = 255) and (O[3 * X
+ 2] = 255)) then
begin
if (((Q[3 * (X - 1)] = 0) and (Q[3 * (X - 1) + 1] = 0)
and (Q[3 * (X - 1) + 2] = 0)) or ((Q[3 * (X + 1)]
= 0)
and (Q[3 * (X + 1) + 1] = 0) and
(Q[3 * (X + 1) + 2] = 0))) then
O[3 * X] := 0;
O[3 * X + 1] := 0;
O[3 * X + 2] := 0;
end;
end;
end;
result := True;
end;
function TMyPicture.BitmapErose(Bitmap: TBitmap; Horic: Boolean): Boolean;
var
X, Y: integer;
newbmp: TBitmap;
P, Q, R, O: pByteArray;
{ IWidth, IHeight: integer;
BA: array of array of Boolean;
procedure GetBAValue;
var
X, Y: integer;
P: pByteArray;
begin
SetLength(BA, IWidth, IHeight);
begin
for Y := 0 to IHeight - 1 do
begin
P := bitmap.ScanLine[Y];
for X := 0 to IWidth - 1 do
begin
BA[X][Y] := ((P[3 * X + 2]) < 128);
end;
end;
end;
end; }
begin
newbmp := TBitmap.Create;
//动态创建位图
newbmp.Assign(bitmap);
// Horic标志是水平方向还是竖直方向腐蚀
if (Horic) then
begin
for Y := 1 to newbmp.Height - 2 do
begin
O := bitmap.ScanLine[Y];
P := newbmp.ScanLine[Y - 1];
Q := newbmp.ScanLine[Y];
R := newbmp.ScanLine[Y + 1];
for X := 1 to newbmp.Width - 2 do
begin
if