procedure TForm1.nteEqualize(bmp:Tbitmap);
var
lTemp,i,j:longint;
bMap:array[0..255] of byte;// 灰度映射表
lCount:array[0..255] of integer;// 灰度映射表
p: pbyteArray;
lheight,llongint;
begin
lheight:=bmp.Height;
l=bmp.Width;
bmp.PixelFormat:=pf8bit;
for i:=0 to 255 do
begin
lCount[i] := 0;
end;
for i:=0 to lHeight-1 do
begin
p:=bmp.ScanLine[i];
for j:=0 to lWidth-1 do
inc(lcount[p[i]]); // 计数加1
end;
// 计算灰度映射表
for i:=0 to 255 do
begin
lTemp := 0;// 初始为0
for j:=0 to i do
begin
lTemp := lTemp+lCount[j];
end;
// 计算对应的新灰度值
bMap[i] := byte(Round(lTemp * 255 / lHeight / lWidth));
end;
for i:=0 to bmp.Height-1 do
begin
p:=bmp.ScanLine[lHeight - 1 - i];
for j:=0 to bmp.Width-1 do
p[j]:=bmap[p[j]];
end;
end;