拉普拉斯源代碼~~~~~~
uj5u.com熱心網友回復:
我現在也在找這人演算法的代碼,雖然找到了很多原始碼,可是代碼如何修改都不適用,其中在<Visual C++數字影像處理與工程案例>第52頁倒有一個演算法,可是代碼寫的太亂了,如何你找不到其他原始碼,就看這個吧,然后慢慢蛋疼。。。。uj5u.com熱心網友回復:
...var
//拉普拉斯系數
tem:array[0..8] of double=(
-1,-1,-1,
-1, 9,-1,
-1,-1,-1
);
procedure TForm1.Button1Click(Sender: TObject);
var
fs:TFileStream;
pBI:PBitmapInfoHeader;
buf,FPDIBBits:PByte;
FWidth:Integer;
FHeight,FLineBytes:Integer;
procedure Templete(tem: array of double; tem_W, tem_H: Integer;
xishu: double);
var
i,j,m,n,midW1,midH1,midW2,midH2,counts:Integer;
sum:Double;
pBuf:PByte;
begin
midW1:=Trunc((tem_W-1)/2);
midW2:=Trunc((tem_W+1)/2);
midH1:=Trunc((tem_H-1)/2);
midH2:=Trunc((tem_H+1)/2);
counts:=FLineBytes*FHeight;
GetMem(pBuf,counts);
Move(FPDIBBits^,pBuf^,counts);
for i:=0 to FHeight-1 do
for j:=0 to FWidth-1 do
begin
sum:=0;
if ((j<Trunc((tem_W-1)/2)) or (j>FWidth-midW2) or
(i<Trunc((tem_H-1)/2)) or (i>FHeight-midH2)) then
else begin
for m:=i-midH1 to i+midH1 do
for n:=j-midW1 to j+midW1 do
sum:=sum+PByte(Integer(FPDIBBits)+FLineBytes*m+n)^*tem[(m-i+midH1)*tem_W+n-j+midW1];
sum:=abs(sum*xishu);
if sum>255 then sum:=255;
PByte(Integer(pBuf)+FLineBytes*i+j)^:=Trunc(sum);
end;
end;
Move(pBuf^,FPDIBBits^,counts);
FreeMem(pBuf);
end;
begin
fs:=TFileStream.Create('c:\lena.bmp',fmOpenRead);
try
GetMem(buf,fs.Size);
fs.ReadBuffer(buf^,fs.Size);
finally
fs.Free;
end;
if PWord(buf)^<>$4D42 then
begin
FreeMem(buf);
ShowMessage('不是位圖檔案.');
exit;
end;
pBI:=PBitmapInfoHeader(Cardinal(buf)+sizeof(TBitmapFileHeader));
//只處理8位位圖
if pBI.biBitCount<>8 then exit;
FWidth:=pBI.biWidth;
FHeight:=abs(pBI.biHeight);
pBI.biClrUsed:=256;
FPDIBBits:=PByte(Cardinal(buf)+sizeof(TBitmapFileHeader)+sizeof(TBitmapInfoHeader)+
pBI.biClrUsed*sizeof(TRGBQuad));
FLineBytes:=Trunc((FWidth*8+31) div 32*4);
Templete(tem,3,3,1);
SetDIBitsToDevice(Canvas.Handle,0,0,FWidth,FHeight,0,0,0,FHeight,FPDIBBits,
PBITMAPINFO(Cardinal(buf)+sizeof(TBitmapFileHeader))^,DIB_RGB_COLORS);
FreeMem(buf);
end;
代碼也是參照了c++代碼.
uj5u.com熱心網友回復:
代碼是否有效?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/116088.html
