在視覺測量中我們很會被毛刺問題困擾,產生干擾的因素很多,有打光問題和產品本生帶毛刺,接下來給兄弟們帶來兩種去毛刺的方法。
第一種
read_image (Image1323153Ba0b96cf52f88f1, '1')
rgb1_to_gray (Image1323153Ba0b96cf52f88f1, GrayImage)
laplace_of_gauss (GrayImage, ImageLaplace, 0.5)
threshold_sub_pix (ImageLaplace, Border, 1)
select_obj (Border, ObjectSelected, 1)
smooth_contours_xld (ObjectSelected, SmoothedContours, 15)
get_contour_xld (SmoothedContours, Row1, Col1)
get_contour_xld (ObjectSelected, Row2, Col2)
*錯誤距離閾值
errdist:=0.5
distRow:= sqrt((Row1-Row2)*(Row1-Row2)+(Col1-Col2)*(Col1-Col2))
a:=find(distRow[>]errdist,1)
e:=Row2[a]
g:=Col2[a]
dev_display (Image1323153Ba0b96cf52f88f1)
gen_cross_contour_xld (Cross, e, g, 10, 0.785398)
運行結果
image.png
image.png
第二種
read_image(Image,'1')
get_image_size(Image,Width,Height)
dev_close_window()
dev_open_window(0,0,Width/3,Height/3,'black',WindowHandle)
dev_set_draw ('margin')
dev_set_color ('cyan')
dev_set_line_width(2)
rgb1_to_gray(Image,GrayImage)
dev_display(GrayImage)
*鼠標畫你要找的roi區域
draw_rectangle1(WindowHandle,Row1,Column1,Row2,Column2)
*顯示roi區域
gen_rectangle1(roi1, Row1, Column1, Row2, Column2)
*減少其他區域,顯示你畫的roi區域
reduce_domain(GrayImage,roi1,ImageReduced)
threshold (ImageReduced, Regions, 200, 255)
opening_circle(Regions,ReigionsoOpening,3.5)
closing_circle(ReigionsoOpening,ReigionsoClosibng,3.5)
*fill_up(ReigionsoClosibng,ReigionFillup)
*boundary(ReigionFillup,ReigionBoundary,'outer')
*ilation_circle(ReigionBoundary,ReigionDilation,1)
reduce_domain(Image,ReigionsoClosibng,ImageReduced1)
gen_contour_region_xld(ImageReduced1,Contours, 'border')
*edges_sub_pix(ImageReduced1,Edges,'canny',1,10,60)
dev_display(ImageReduced1)
dev_display(Contours)
stop()
*根據長度裁剪
select_shape_xld(Contours, AreaEdges1, 'contlength', 'and', 50, 9999)
*根據xld找尋區域輪廓的所有x,y坐標
count_obj (AreaEdges1, Number)
*遍歷亞像素坐標點
y2:=[]
x2:=[]
for x := 0 to Number-1 by 1
select_obj (AreaEdges1, ObjectSelected, x+1)
get_contour_xld (ObjectSelected, Row, Column)
y2 := [Row, y2]
x2 := [Column, x2]
endfor
*找最大最小x,y
min_x:=min(x2)
max_x:=max(x2)
min_y:=min(y2)
max_y:=max(y2)
*畫直線
disp_line (WindowHandle, min_y,min_x , min_y, max_x)
disp_line (WindowHandle, min_y,min_x ,max_y , min_x)
disp_line (WindowHandle, max_y , min_x, max_y, max_x)
disp_line (WindowHandle, max_y, max_x, min_y, max_x)
運行結果
image.png
image.png
有什么需求,可以評論一起探討思路