Read_image (Image, 'D:/1.bmp') get_image_size (Image, Width, Height) * Count_channels (Image, Channels) if (Channels == 3 or Channels == 4) rgb1_to_gray (Image, Edges_sub_pix (Image, Edges, 'lanser1', 1, 5, Edges); 10) * Merge adjacent XLD, make small line segments join union_adjacent_contours_xLD (Edges, UnionContours, 5, 1, 'attr_keep') * Select XLD * according to the contour features. The operator uses the following contour features: contour length, direction, contour return line direction, using parameters min1, max1; * Curvature, average distance from contour XLD to regression line and standard deviation range are selected, average distance using parameters min1, max1; * Standard deviation min2, max2, the condition is within the size range of the two parameters. Select_contours_xld (UnionContours, SelectedContours, 'contour_length', 20, 999999, -0.5, Count_obj (SelectedContours, NumberContours) for I := 1 to NumberContours by 1 select_obj (SelectedContours, ObjectSelected, i) get_contour_xld (ObjectSelected, row, col) endfor dev_set_color ('green') dev_display (Image) dev_display (Edges) dev_display (SelectedContours) stop() R:= 1 gen_image_const (ConstImage, 'byte', 2*R+1, 2*R+1) MaskHeight) gen_circle (Circle, (maskheight-1) / 2.0, (maskwidth-1) / 2.0, R) reduce_domain (ConstImage, Circle, ImageReduced) gray_closing (Image, ImageReduced, ImageClosing) * gray_closing_shape(Image, ImageClosing, R, R, Edges_sub_pix (ImageClosing, Edges, 'lanser1', 1, 5, Edges) * Subpixel extraction edge, the larger the Alpha value, the smoother the contour. 10) * Merge adjacent XLD, make small line segments join union_adjacent_contours_xLD (Edges, UnionContours, 5, 1, 'attr_keep') * Select XLD * according to the contour features. The operator uses the following contour features: contour length, direction, contour return line direction, using parameters min1, max1; * Curvature, average distance from contour XLD to regression line and standard deviation range are selected, average distance using parameters min1, max1; * Standard deviation min2, max2, the condition is within the size range of the two parameters. Select_contours_xld (UnionContours, SelectedContours, 'contour_length', 100, 999999, -0.5, 0.5) count_obj (SelectedContours, NumberContours) maxArea := 0 index := 0 for i := 1 to NumberContours by 1 select_obj (SelectedContours, ObjectSelected, i) area_center_xld (ObjectSelected, Area, Row1, Column1, PointOrder) if (Area > maxArea) maxArea := Area index := i endif endfor select_obj (SelectedContours, ObjectSelected, Index) get_contour_xld (ObjectSelected, Row2, Column2) stop() * Invalid set_system ('init_new_image', 'false') gen_region_contour_xld (ObjectSelected, Region, 'filled') gen_image_const (NewImage, 'byte', Width, Height) *Create an image with a specified constant gray value gen_image_proto (NewImage, ImageCleared1, 255) *Paint regions into an image paint_region (Region, ImageCleared1, ImageResult, 0, 'fill') write_image (ImageResult, 'jpeg', 0, 'D:/1111.jpg') *Overpaint regions in an image gen_image_proto (NewImage, ImageCleared2, 255) overpaint_region(ImageCleared2, Region, 0, 'fill') * Get_image_size (ConstImage, MaskWidth, MaskHeight) gen_circle (Circle, (maskheight-1) / 2.0, (MaskWidth -1) / 2.0, R) reduce_domain (ConstImage, Circle, ImageReduced) gray_Erosion (ImageResult, ImageReduced, ImageErosion) edges_sub_pix (ImageErosion, EdgesErosion, 'lanser1', 1, 5, 10) count_obj(EdgesErosion, NumberContours) if (NumberContours == 1) get_contour_xld (EdgesErosion, Row3, Column3) endif stop()Copy the code

 

Morphologically related operators:

erosion1

erosion_circle

gray_erosion

gray_dilation

gray_opening

gray_closing

 

— Official case

gray_opening.hdev

count_pellets.hdev