主题:图像处理 数格子
怎么可以输出格子的条数?
格子间的距离?
谢谢高手指点
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, StdCtrls, ExtCtrls, math;
type
TMyPicture = class(TForm)
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Button1: TButton;
Button3: TButton;
Button5: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(sender: TObject );
procedure Button5Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure PictureTwoValue(Bitmap: TBitmap);
// 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}
procedure TMyPicture.FormCreate(Sender: TObject);
begin
Self.DoubleBuffered := true;
backbmp := Tbitmap.create;
backbmp.assign(Image1.picture.bitmap);
end;
procedure TMyPicture.Button1Click(Sender: TObject);
begin
PictureTwoValue(image1.Picture.Bitmap);
end;
procedure TMyPicture.Button3Click(Sender: TObject);
begin
self.OpenPictureDialog1.Filter := '*.bmp|*.bmp';
if OpenPictureDialog1.Execute then
begin
Image1.picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
end;
end;
procedure TMyPicture.Button5Click(Sender: TObject);
var
x,y,n: integer;
newbmp: TBitmap;
P, Q, R, O: pByteArray;
begin
n:=0;
newbmp := TBitmap.Create;
//动态创建位图
newbmp.Assign(Image1.Picture.Bitmap);
for y := 1 to newbmp.Height - 2 do
begin
O := newbmp .ScanLine[y];
P := newbmp.ScanLine[y - 2];
Q := newbmp.ScanLine[y];
R := newbmp.ScanLine[y + 2];
begin
x:=450;
if ((O[3 * x] = 255) and (O[3 * x + 1] = 255) and (O[3 * x + 2]
= 255)) then
begin
if (((Q[3 * (x - 1)] = 255) and (Q[3 * (x - 1) + 1] =255) and (Q[3 * (x - 1) + 2] = 255))
and((Q[3 * (x+1)] = 255)and (Q[3 * (x + 1) + 1] = 255) and(Q[3 * (x + 1) + 2] = 255))
and ((P[3 * x] = 255) and(P[3 * x + 1] = 255) and (P[3 * x + 2] = 255)
and(p[3*(x-1)+1]=255)and(p[3*(x-1)]=255)and (p[3*(x-1)+2]=255)
and(p[3*(x+1)+1]=255)and(p[3*(x+1)]=255)and (p[3*(x+1)+2]=255))
and ((R[3 * x] = 0) and (R[3 * x + 1] = 0) and(R[3* x + 2] = 0)
and(R[3*(x-1)+1]=0)and(R[3*(x-1)]=0)and (R[3*(x-1)+2]=0)
and(R[3*(x+1)+1]=0)and(R[3*(x+1)]=0)and (R[3*(x+1)+2]=0)))
then
begin
n:=n+1;
Label1 .caption:=IntToStr(n);
end;
end;
end;
end;
end;
procedure TMyPicture.PictureTwoValue(Bitmap: TBitmap);
var
X, Y: integer;
P: pByteArray;
newbmp: TBitmap;
gray: byte;
begin
newbmp := TBitmap.Create;
newbmp.PixelFormat := bitmap.PixelFormat;
newbmp.Assign(bitmap);
for Y := 0 to bitmap.Height - 1 do
begin
P := newbmp.ScanLine[Y];
for X := 0 to bitmap.Width - 1 do
begin
gray := Round(0.299 * P[3 * X + 2] + 0.587 * P[3 * X + 1] + 0.11
*
P[3 * X]);
// 灰化的计算公式
if (gray > 225) then
gray := 255
else
gray := 0;
// 225为阙值
P[3 * X + 2] := gray;
P[3 * X + 1] := gray;
P[3 * X] := gray;
end;
end;
bitmap.Assign(newbmp);
end;
procedure TMyPicture.FormClose(Sender: TObject; var Action: TCloseAction);
begin
backbmp.free;
end;
end.
格子间的距离?
谢谢高手指点
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, StdCtrls, ExtCtrls, math;
type
TMyPicture = class(TForm)
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Button1: TButton;
Button3: TButton;
Button5: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(sender: TObject );
procedure Button5Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure PictureTwoValue(Bitmap: TBitmap);
// 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}
procedure TMyPicture.FormCreate(Sender: TObject);
begin
Self.DoubleBuffered := true;
backbmp := Tbitmap.create;
backbmp.assign(Image1.picture.bitmap);
end;
procedure TMyPicture.Button1Click(Sender: TObject);
begin
PictureTwoValue(image1.Picture.Bitmap);
end;
procedure TMyPicture.Button3Click(Sender: TObject);
begin
self.OpenPictureDialog1.Filter := '*.bmp|*.bmp';
if OpenPictureDialog1.Execute then
begin
Image1.picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
end;
end;
procedure TMyPicture.Button5Click(Sender: TObject);
var
x,y,n: integer;
newbmp: TBitmap;
P, Q, R, O: pByteArray;
begin
n:=0;
newbmp := TBitmap.Create;
//动态创建位图
newbmp.Assign(Image1.Picture.Bitmap);
for y := 1 to newbmp.Height - 2 do
begin
O := newbmp .ScanLine[y];
P := newbmp.ScanLine[y - 2];
Q := newbmp.ScanLine[y];
R := newbmp.ScanLine[y + 2];
begin
x:=450;
if ((O[3 * x] = 255) and (O[3 * x + 1] = 255) and (O[3 * x + 2]
= 255)) then
begin
if (((Q[3 * (x - 1)] = 255) and (Q[3 * (x - 1) + 1] =255) and (Q[3 * (x - 1) + 2] = 255))
and((Q[3 * (x+1)] = 255)and (Q[3 * (x + 1) + 1] = 255) and(Q[3 * (x + 1) + 2] = 255))
and ((P[3 * x] = 255) and(P[3 * x + 1] = 255) and (P[3 * x + 2] = 255)
and(p[3*(x-1)+1]=255)and(p[3*(x-1)]=255)and (p[3*(x-1)+2]=255)
and(p[3*(x+1)+1]=255)and(p[3*(x+1)]=255)and (p[3*(x+1)+2]=255))
and ((R[3 * x] = 0) and (R[3 * x + 1] = 0) and(R[3* x + 2] = 0)
and(R[3*(x-1)+1]=0)and(R[3*(x-1)]=0)and (R[3*(x-1)+2]=0)
and(R[3*(x+1)+1]=0)and(R[3*(x+1)]=0)and (R[3*(x+1)+2]=0)))
then
begin
n:=n+1;
Label1 .caption:=IntToStr(n);
end;
end;
end;
end;
end;
procedure TMyPicture.PictureTwoValue(Bitmap: TBitmap);
var
X, Y: integer;
P: pByteArray;
newbmp: TBitmap;
gray: byte;
begin
newbmp := TBitmap.Create;
newbmp.PixelFormat := bitmap.PixelFormat;
newbmp.Assign(bitmap);
for Y := 0 to bitmap.Height - 1 do
begin
P := newbmp.ScanLine[Y];
for X := 0 to bitmap.Width - 1 do
begin
gray := Round(0.299 * P[3 * X + 2] + 0.587 * P[3 * X + 1] + 0.11
*
P[3 * X]);
// 灰化的计算公式
if (gray > 225) then
gray := 255
else
gray := 0;
// 225为阙值
P[3 * X + 2] := gray;
P[3 * X + 1] := gray;
P[3 * X] := gray;
end;
end;
bitmap.Assign(newbmp);
end;
procedure TMyPicture.FormClose(Sender: TObject; var Action: TCloseAction);
begin
backbmp.free;
end;
end.