本帖最后由 1030985286 于 2023-8-4 17:15 编辑
我通过灰度的腐蚀膨胀将盖子筛选出来,再减去得到没有盖子的区域,料种类和亮度都不一样,对于我这个初学者来说太难了
read_image (Image11, read_image (Image11, 'C:/Users/Admin/Downloads/11.bmp')
get_image_size (Image11, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width/2.5, Height/2.5, 'black', windowhandle)
dev_display (Image11)
draw_rectangle2 (windowhandle, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
reduce_domain (Image11, Rectangle, ImageReduced)
vector_angle_to_rigid (Row, Column, Phi, Row, Column, 0, HomMat2D)
affine_trans_region (Rectangle, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
affine_trans_image (ImageReduced, ImageAffineTrans, HomMat2D, 'constant', 'false')
reduce_domain (ImageAffineTrans, RegionAffineTrans, ImageReduced1)
*款式太多,图15,16需要和边缘分离,没有实现
intensity (Rectangle, Image11, Mean, Deviation)
*亮度高的用灰度膨胀,暗的用灰度腐蚀,将盖子筛选出来,将所有区域减去盖子,得出没有盖子的区域
if (Mean<100)
*找出有盖的地方
gray_erosion_rect (ImageReduced1, ImageMin, 11, 11)
mean_image (ImageMin, ImageMean, 61,61)
dyn_threshold (ImageMin, ImageMean, RegionDynThresh, 5, 'light')
connection (RegionDynThresh, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['area','circularity'], 'and', [650,0.5], [4500,1])
smallest_circle (SelectedRegions, Row2, Column2, Radius1)
gen_circle (Circle1, Row2, Column2, Radius1)
dev_display (ImageAffineTrans)
dev_display (Circle1)
else
gray_dilation_rect (ImageReduced1, ImageMax, 11, 11)
mean_image (ImageMax, ImageMean1, 61, 61)
dyn_threshold (ImageMax, ImageMean1, RegionDynThresh1, 20, 'dark')
connection (RegionDynThresh1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, ['area','circularity'], 'and', [650,0.5], [4500,1])
smallest_circle (SelectedRegions1, Row1, Column1, Radius)
gen_circle (Circle, Row1, Column1, Radius)
dev_display (ImageAffineTrans)
dev_display (Circle)
endif
|