【图像处理高级编程】-图像的代数与图像分割

本文档介绍了图像处理中图像代数的概念,并提供了图像分割的源码实现,包括图像的腐蚀与膨胀操作。通过二值化、细化等方法,实现了对图像的处理和分析。此外,还探讨了Sobel算子和模板滤波在边缘检测中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图像的代数与图像分割

提示:这里可以添加技术概要

请添加图片描述

核心源码

{------------------------------------

  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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大龙软件研发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值