2024年3月27日发(作者:)

图像的处理(一)----灰度图像像素颜色亮度处理

以前看了一些有关图像处理的书,对我起到了很大的帮助。所以,今天我就将我学过

的知识整理出来,一方面可以给人学习,另一方面也可以请各位高手指点指点。

我要说的图像处理是针对程序方面的。所以,先做一个程序来放置图形。在这里,我

使用了Delphi作为工具。因为,在我使用过的众多编译器当中,Delphi对图形的支持最好。

还有,这里我并不是讲语法。所以,有些代码我就不详细说明。不便之处,敬请原谅。

注意:本文章的示例程序所用的东西不超过GDI的范围。

在图像处理中,速度是很重要的。因此,我们得重新处理一下TBitmap,得到

TVczhBitmap。这只是因为GetPixels和SetPixels的速度太慢,换一个方法而已。

unit untBitmapProc;

interface

uses Graphics, SysUtils;

type

TVczhBitmap=class(TBitmap)

private

Data:PByteArray;

Line:Integer;

procedure SetFormat;

function GetBytePointer(X,Y:Integer):PByte;

procedure SetBytes(X,Y:Integer;Value:Byte);

function GetBytes(X,Y:Integer):Byte;

protected

published

constructor Create;

public

property Bytes[X,Y:Integer]:Byte read GetBytes write SetBytes;

procedure LoadFromFile(FileName:String);

procedure ToGray;

end;

implementation

procedure mat;

begin

HandleType:=bmDIB;

PixelFormat:=pf24bit;

end;

function ePointer(X,Y:Integer):PByte;

begin

if Line<>Y then

begin

Line:=Y;

Data:=ScanLine[Y];

end;

Longint(result):=Longint(Data)+X;

end;

procedure es(X,Y:Integer;Value:Byte);

begin

GetBytePointer(X,Y)^:=Value;

end;

function es(X,Y:Integer):Byte;

begin

result:=GetBytePointer(X,Y)^;

end;

constructor ;

begin

inherited Create;

SetFormat;

Line:=-1;

end;

procedure omFile(FileName:String);

begin

inherited LoadFromFile(FileName);

SetFormat;

Line:=-1;

end;

procedure ;

var X,Y,R:Integer;

B:Byte;

begin

for Y:=0 to Height-1 do

for X:=0 to Width-1 do

begin

R:=0;

for B:=0 to 2 do

R:=R+GetBytes(X*3+B,Y);

for B:=0 to 2 do