在视觉测量中我们很会被毛刺问题困扰,产生干扰的因素很多,有打光问题和产品本生带毛刺,接下来给兄弟们带来两种去毛刺的方法。
第一种
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
网友评论