能解释一下Delphi自带的例子吗? 我不知道变量P在其中的作用 我的简单理解: Bitbmp读入图像后,经过scanline后,P中就有值了, 但在后面好像与P没有关系了??procedure TForm1.Button1Click(Sender: TObject); var x,y : Integer; BitMap : TBitMap; P : PByteArray; begin BitMap := TBitMap.create; try BitMap.LoadFromFile('C:\Documents and Settings\zcm\My Documents\My Pictures\mt097_1.bmp'); BitMap.width:=200; BitMap.Height:=345; Bitmap.PixelFormat:= pf24bit; for y := 0 to (BitMap.Height -1) do begin P := BitMap.ScanLine[y]; for x := 0 to (BitMap.Width -1) do P[x] := y; end; Canvas.Draw(0,0,BitMap); finally BitMap.Free; end; end;
//intPeak、intPeak2、intValley:峰值和直方图值 //intIndx::相应的灰度值intPeak,intIndx,intPeak2,intIndx2,intValley,intValleyIndx:integer;//初始双峰值 intPeak:=0; intPeak2:=0;//取得第一峰值 for intLoop:=0 to 255 do if intPeak<=intGrayLevel[intLoop] then begin intPeak:=intGrayLevel[intLoop]; intIndx:=intLoop; end;//取得第二峰值 for intLoop:=0 to 255 do Begin if (intPeak2<=intGrayLevel[intLoop]) and (intLoop<>intIndx) then begin intPeak2:=intGrayLevel[intLoop]; intIndx2:=intLoop; end; end;//取得双峰之间的谷值 intValley:=intSize; if intIndx2<intIndx then for intLoop:=intIndx2 to intIndx do if intValley>intGrayLevel[intLoop] then begin intValley:=intGrayLevel[intLoop]; intValleyIndx:=intLoop; end;
或找到VC的源码也行,翻成Delphi的。原理,我和extcsd已经说得很明白了。
所以,现在问题主要集中在如何对图像进行灰度直方图统计。
这个出来了,闽值也就出来了。闽值出来了,对图像做二值化,
用ScanLine对图像遍历一次不就OK了吗?所以你先查如何对图像进行灰度直方图统计,就可以了。
用法,
问题:有关ScanLine ( 积分:50, 回复:3, 阅读:50 )
分类:图形图象 ( 版主:卷起千堆雪tyn, menxin )
来自:Nstar, 时间:2003-02-11 15:08:00, ID:1615658 [显示:小字体 | 大字体]
能解释一下Delphi自带的例子吗?
我不知道变量P在其中的作用
我的简单理解:
Bitbmp读入图像后,经过scanline后,P中就有值了,
但在后面好像与P没有关系了??procedure TForm1.Button1Click(Sender: TObject);
var
x,y : Integer;
BitMap : TBitMap;
P : PByteArray;
begin
BitMap := TBitMap.create;
try
BitMap.LoadFromFile('C:\Documents and Settings\zcm\My Documents\My Pictures\mt097_1.bmp');
BitMap.width:=200;
BitMap.Height:=345;
Bitmap.PixelFormat:= pf24bit;
for y := 0 to (BitMap.Height -1) do
begin
P := BitMap.ScanLine[y];
for x := 0 to (BitMap.Width -1) do
P[x] := y;
end;
Canvas.Draw(0,0,BitMap);
finally
BitMap.Free;
end;
end;
//intIndx::相应的灰度值intPeak,intIndx,intPeak2,intIndx2,intValley,intValleyIndx:integer;//初始双峰值 intPeak:=0;
intPeak2:=0;//取得第一峰值 for intLoop:=0 to 255 do
if intPeak<=intGrayLevel[intLoop] then
begin
intPeak:=intGrayLevel[intLoop];
intIndx:=intLoop;
end;//取得第二峰值 for intLoop:=0 to 255 do
Begin
if (intPeak2<=intGrayLevel[intLoop]) and (intLoop<>intIndx) then
begin
intPeak2:=intGrayLevel[intLoop];
intIndx2:=intLoop;
end;
end;//取得双峰之间的谷值
intValley:=intSize; if intIndx2<intIndx then
for intLoop:=intIndx2 to intIndx do
if intValley>intGrayLevel[intLoop] then
begin
intValley:=intGrayLevel[intLoop];
intValleyIndx:=intLoop;
end;