期望结果完全相同,但是下面的测试结果和halcon的差值如下:
[0.132838, 0.231991, 0.265157, 0.296903, 0.0998573, 0.165907, 0.230686, 0.130266, 0.0977104, 0.197109, 0.198173, 0.197086, 0.190943, 0.177665, 0.163521, 0.146541, 0.161362, 0.166666, 0.22818, 0.186114, 0.196333, 0.255945, 0.14496, 0.205199, 0.262202, 0.201859, 0.173616, 0.173016, 0.173485, 0.173227, 0.171494, 0.257541, 0.171186, 0.141769, 0.0852231, 0.257203, 0.198859, 0.170551, 0.25673, 0.171491, 0.170175, 0.169464, 0.198114, 0.169922, 0.169473, 0.1695, 0.168997, 0.139408, 0.195358, 0.193962, 0.221091, 0.19246, 0.246518, 0.138458, 0.194492, 0.193142, 0.217299, 0.188277, 0.16121, 0.106746, 0.106695, 0.104717, 0.154996, 0.17956, 0.199884, 0.174948, 0.174217, 0.125464, 0.234857, 0.197361, 0.239242, 0.217724, 0.220922, 0.160648, 0.19362, 0.1959, 0.196964, 0.197266, 0.229685, 0.193291, 0.191924, 0.191487, 0.288308, 0.191503, 0.223271, 0.285233, 0.0954785, 0.157538, 0.187701, 0.284095, 0.190475, 0.18948, 0.188329, 0.187838, 0.186164, 0.217482, 0.277055, 0.215032, 0.15109, 0.27215, 0.211512, 0.208731, 0.286509, 0.262083, 0.31329, 0.315317, 0.358043, 0.396789, 0.403176, 0.397609, 0.39305, 0.392336, 0.19589, 0.260681, 0.459158, 0.330526, 0.19935, 0.587357, 0.518498, 0.44198, 0.24967]
结果并不小,不知道问题出在哪里?
get_grayval_interpolated 和自己实现的双线性差值的结果是完全相同的
dev_close_window()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_set_window (WindowHandle)
read_image (Image, 'fabrik')
get_image_size (Image, Width, Height)
CenterRow:=Height/2-50
CenterCol:=Width/2
degPhi:=45
Phi:=rad(degPhi)
Length1:=60
Length1:=int(floor(Length1))
Length2:=1
gen_measure_rectangle2 (CenterRow, CenterCol, -Phi, Length1, Length2, Width, Height, 'bilinear', MeasureHandle)
measure_projection (Image, MeasureHandle, GrayValues)
disp_rectangle2(WindowHandle,CenterRow, CenterCol, -Phi, Length1, Length2)
RowAry:=[]
ColAry:=[]
RowAry[Length1]:=CenterRow
ColAry[Length1]:=CenterCol
RowOffsetAry[Length2]:=0
ColOffsetAry[Length2]:=0
clockWise:=true
if(clockWise)
Phi2:=rad(degPhi-90)
else
Phi2:=rad(degPhi+90)
endif
RowOffsetStep:=sin(Phi2)
ColOffsetStep:=cos(Phi2)
for Index := 1 to Length2 by 1
RowOffsetAry[Length2+Index]:=RowOffsetStep*Index
ColOffsetAry[Length2+Index]:=ColOffsetStep*Index
RowOffsetAry[Length2-Index]:=-RowOffsetAry[Length2+Index]
ColOffsetAry[Length2-Index]:=-ColOffsetAry[Length2+Index]
endfor
gen_image_const (Image1, 'real', Length1*2+1, Length2*2+1)
get_image_size (Image1, Width1, Height1)
RowOffsetStep:=sin(Phi)
ColOffsetStep:=cos(Phi)
for Index := 1 to Length1 by 1
RowAry[Length1+Index]:=CenterRow+Index*RowOffsetStep
ColAry[Length1+Index]:=CenterCol+Index*ColOffsetStep
RowAry[Length1-Index]:=CenterRow-Index*RowOffsetStep
ColAry[Length1-Index]:=CenterCol-Index*ColOffsetStep
endfor
GrayValues2:=[]
copy_image(Image, DupImage)
for Index := 0 to Width1-1 by 1
get_grayval_interpolated (Image, RowAry[Index], ColAry[Index], 'bilinear', Grayval)
left:= int(floor(ColAry[Index]))
right:=left+1
top:= int(floor(RowAry[Index]))
bottom:=top+1
a:=ColAry[Index]-left
b:=RowAry[Index]-top
get_grayval(Image,top,left,topLeftGrayVal)
get_grayval(Image,top,right,topRightGrayVal)
get_grayval(Image,bottom,left,bottomLeftGrayVal)
get_grayval(Image,bottom,right,bottomRightGrayVal)
Grayval:=(1 - a)*(1 - b)*topLeftGrayVal+ a*(1 - b)*topRightGrayVal +(1 - a)*b*bottomLeftGrayVal + a*b*bottomRightGrayVal
set_grayval (Image1, Length2, Index, Grayval)
set_grayval(DupImage,int(RowAry[Index]),int(ColAry[Index]),0)
AVGGrayVal:=Grayval
for Index2 := 1 to Length2 by 1
Row:=RowAry[Index]+RowOffsetAry[Length2+Index2]
Col:=ColAry[Index]+ColOffsetAry[Length2+Index2]
get_grayval_interpolated (Image, Row, Col, 'bilinear', Grayval)
left:= int(floor(Col))
right:=left+1
top:= int(floor(Row))
bottom:=top+1
a:=Col-left
b:=Row-top
get_grayval(Image,top,left,topLeftGrayVal)
get_grayval(Image,top,right,topRightGrayVal)
get_grayval(Image,bottom,left,bottomLeftGrayVal)
get_grayval(Image,bottom,right,bottomRightGrayVal)
Grayval:=(1 - a)*(1 - b)*topLeftGrayVal+ a*(1 - b)*topRightGrayVal +(1 - a)*b*bottomLeftGrayVal + a*b*bottomRightGrayVal
set_grayval (Image1, Length2+Index2, Index, Grayval)
set_grayval(DupImage,int(Row),int(Col),0)
AVGGrayVal:=AVGGrayVal+Grayval
Row:=RowAry[Index]+RowOffsetAry[Length2-Index2]
Col:=ColAry[Index]+ColOffsetAry[Length2-Index2]
get_grayval_interpolated (Image, Row, Col, 'bilinear', Grayval)
left:= int(floor(Col))
right:=left+1
top:= int(floor(Row))
bottom:=top+1
a:=Col-left
b:=Row-top
get_grayval(Image,top,left,topLeftGrayVal)
get_grayval(Image,top,right,topRightGrayVal)
get_grayval(Image,bottom,left,bottomLeftGrayVal)
get_grayval(Image,bottom,right,bottomRightGrayVal)
Grayval:=(1 - a)*(1 - b)*topLeftGrayVal+ a*(1 - b)*topRightGrayVal +(1 - a)*b*bottomLeftGrayVal + a*b*bottomRightGrayVal
set_grayval (Image1, Length2-Index2, Index, Grayval)
set_grayval(DupImage,int(Row),int(Col),0)
AVGGrayVal:=AVGGrayVal+Grayval
endfor
AVGGrayVal:=AVGGrayVal/Height1
GrayValues2[Index]:=AVGGrayVal
endfor
for Index := 0 to |GrayValues2|-1 by 1
GrayValuesDidff[Index]:=GrayValues2[Index]-GrayValues[Index]
endfor