* This program gets the deviation between
* circular contours and their best fitting circles
*dev_update_var('off')dev_update_off()** step: acquire image and initialize the visualization
*read_image(Image,'pumpe')get_image_size(Image, Width, Height)dev_close_window()dev_open_window(0,0, Width, Height,'light gray', WindowID)dev_set_part(0,0, Height -1, Width -1)dev_set_line_width(1)dev_set_color('red')dev_set_draw('margin')dev_display(Image)set_display_font(WindowID,16,'mono','true','false')disp_continue_message(WindowID,'black','true')stop()** step: create ROI
*fast_threshold(Image, Region,0,70,150)dev_set_colored(3)connection(Region, ConnectedRegions)select_shape(ConnectedRegions, SelectedRegions,['outer_radius','anisometry','area'],'and',[5,1,100],[50,1.8,99999])shape_trans(SelectedRegions, RegionTrans,'outer_circle')dilation_circle(RegionTrans, RegionDilation,5.5)union1(RegionDilation, RegionUnion)reduce_domain(Image, RegionUnion, ImageReduced)dev_clear_window()dev_display(ImageReduced)disp_continue_message(WindowID,'black','true')stop()** step: create and select relevant contours
*threshold_sub_pix(ImageReduced, Border,80)select_shape_xld(Border, SelectedXLD,['contlength','outer_radius'],'and',[70,15],[99999,99999])segment_contours_xld(SelectedXLD, ContoursSplit,'lines_circles',4,2,2)select_shape_xld(ContoursSplit, SelectedXLD3,['outer_radius','contlength'],'and',[15,30],[45,99999])union_cocircular_contours_xld(SelectedXLD3, UnionContours2,0.5,0.1,0.2,2,10,10,'true',1)sort_contours_xld(UnionContours2, SortedContours,'upper_left','true','column')dev_clear_window()dev_set_color('white')dev_display(ImageReduced)dev_display(SortedContours)disp_continue_message(WindowID,'black','true')stop()** step: fit circles into the contours and get the
* average deviation between contour and circle
*count_obj(SortedContours, NumSegments)dev_display(Image)dev_display(SortedContours)
NumCircles :=0disp_message(WindowID,'Circle radius and average distance','window',10,10,'white','false')disp_message(WindowID,'between circle and contour:','window',30,10,'white','false')for i :=1 to NumSegments by 1select_obj(SortedContours, SingleSegment, i)
NumCircles := NumCircles +1fit_circle_contour_xld(SingleSegment,'atukey',-1,2,0,5,2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)gen_circle_contour_xld(ContCircle, Row, Column, Radius,0,rad(360),'positive',1)dev_display(ContCircle)dist_ellipse_contour_xld(SingleSegment,'algebraic',-1,0, Row, Column,0, Radius, Radius, MinDist, MaxDist, AvgDist, SigmaDist)disp_message(WindowID, NumCircles,'window', Row -10, Column -5,'white','false')disp_message(WindowID,'R'+ NumCircles +': '+ Radius$'.3','window',(i -1)*50+30,450,'white','false')disp_message(WindowID,'D_avg: '+ AvgDist$'.3','window',((i -1)*50)+50,450,'white','false')
endfor
*dev_update_window('on')