设置首页收藏本站
开启左侧

如何找到图片中的瑕疵并区分它是不是对称的

[复制链接]
Jescal0001 发表于 2025-2-24 16:07:50 | 显示全部楼层 |阅读模式
悬赏2视觉币
对称性的那两颗是mark
左边那颗是瑕疵 要怎么区分出来
每次角度会不一样,需要抓到对称的那组忽略它(另外标示出来
求大神提供代码
test0001.jpg

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
hankchang 发表于 2025-2-24 16:07:51 | 显示全部楼层
  1. read_image (Image160726c3yzr9itzqu898wi, 'C:/Users/genel/OneDrive/桌面/160726c3yzr9itzqu898wi.jpg')
  2. binary_threshold(Image160726c3yzr9itzqu898wi, Region, 'max_separability', 'dark', UsedThreshold)

  3. connection(Region, ConnectedRegions)
  4. select_shape(ConnectedRegions, SelectedRegions, 'outer_radius', 'and', 1100, 1300)
  5. shape_trans(SelectedRegions, RegionTrans, 'outer_circle')
  6. smallest_circle(SelectedRegions, Row, Column, Radius)
  7. gen_circle(Circle, Row, Column, Radius-80)
  8. difference(RegionTrans, Circle, RegionDifference)

  9. reduce_domain(Image160726c3yzr9itzqu898wi, RegionDifference, ImageReduced)
  10. gray_closing_rect (ImageReduced, ImageClosing, 11, 11)
  11. binary_threshold(ImageClosing, Region1, 'max_separability', 'dark', UsedThreshold1)
  12. connection(Region1, ConnectedRegions1)
  13. select_shape(ConnectedRegions1, SelectedRegions1, 'outer_radius', 'and', 15, 25)

  14. area_center(SelectedRegions1, Area, Row1, Column1)
  15. tuple_gen_sequence(0, |Row1|-1, 1, Sequence)
  16. ***找最大距離 組合
  17. dis:=0
  18. if(|Area|>2)
  19.     si:=-1
  20.     sj:=-1
  21.         for i:=0 to |Row1|-1 by 1
  22.             for j:=i+1 to |Row1|-1 by 1
  23.                 distance_pp(Row1[i], Column1[i], Row1[j], Column1[j], Distance)
  24.                 if(Distance>dis)
  25.                     dis:=Distance
  26.                     si:=i
  27.                     sj:=j
  28.                 endif
  29.             endfor
  30.         endfor
  31. endif

  32. id:=[si,sj]

  33. ***排除正確 剩下就是瑕疵
  34. tuple_remove(Sequence, id, Reduced)
  35. gen_empty_obj(defect)
  36. for i:=0 to |Reduced|-1 by 1
  37.     select_obj(SelectedRegions1, ObjectSelected, Reduced[i]+1)
  38.     concat_obj(defect, ObjectSelected, defect)
  39. endfor

  40. gen_empty_obj(mark)
  41. for i:=0 to |id|-1 by 1
  42.     select_obj(SelectedRegions1, ObjectSelected, id[i]+1)
  43.     concat_obj(mark, ObjectSelected,mark)
  44. endfor
复制代码

2025-02-24 17 33 26.jpg
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

18861175562 发表于 2025-2-24 16:44:32 | 显示全部楼层
把所有的都找出来  挨个遍历求点到点距离  最远的两颗就是对称的  
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

南風 发表于 2025-2-25 13:42:03 | 显示全部楼层
把三个点都提取出来,然后仿射变换,不能重合的就是缺陷
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

 楼主| Jescal0001 发表于 2025-2-25 14:37:15 | 显示全部楼层

感谢 我会用此方法再做修改
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

hankchang 发表于 2025-2-25 15:26:32 | 显示全部楼层
Jescal0001 发表于 2025-2-25 14:37
感谢 我会用此方法再做修改

如後續需要討論 請不要客氣!
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

 楼主| Jescal0001 发表于 2025-2-27 16:17:25 | 显示全部楼层
本帖最后由 Jescal0001 于 2025-2-27 17:00 编辑
hankchang 发表于 2025-2-25 15:26
如後續需要討論 請不要客氣!

感谢大神 目前还有一个问题是 我抓中间那块区域抓得不太准
你可以帮我看一下我的代码吗 谢谢

  1. read_image (Image, '1.jpg')
  2. rgb1_to_gray (Image, GrayImage)
  3. binary_threshold(GrayImage, Region, 'max_separability', 'dark', UsedThreshold)
  4. connection(Region, ConnectedRegions)
  5. select_shape(ConnectedRegions, SelectedRegions, ['outer_radius','roundness','inner_radius'], 'and', [1100,0.8,0], [1300,1,100])
  6. count_obj (SelectedRegions, Number)
  7. if (Number >0)
  8.     is_lens_found := true
  9.     shape_trans (SelectedRegions, Lens, 'convex')
  10. endif


  11. reduce_domain (GrayImage, Lens, ImageReduced)
  12. threshold (ImageReduced, DarkPrintRegions, 0, 90)
  13. opening_circle (DarkPrintRegions, RegionOpening, 10)
  14. closing_circle (RegionOpening, RegionClosing, 50)
  15. connection (RegionClosing, ConnectedRegions1)
  16. select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 200000, 99999999)
  17. fill_up (SelectedRegions1, RegionFillUp1)
  18. shape_trans (RegionFillUp1, Pattern_out, 'convex')
  19. fill_up (RegionClosing, RegionFillUp)
  20. difference (RegionFillUp, RegionClosing, RegionDifference)
  21. inner_circle (RegionDifference, Row, Column, Radius)
  22. gen_circle (Pattern_in, Row, Column, Radius)

  23. difference (Pattern_out, Pattern_in, Pattern)

  24. dev_set_draw ('margin')
  25. dev_display(GrayImage)
  26. dev_display (Pattern)
复制代码



奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

hankchang 发表于 2025-2-27 17:58:41 | 显示全部楼层
本帖最后由 hankchang 于 2025-2-27 18:23 编辑
Jescal0001 发表于 2025-2-27 16:17
感谢大神 目前还有一个问题是 我抓中间那块区域抓得不太准
你可以帮我看一下我的代码吗 谢谢

read_image (Image, 'C:/Users/genel/OneDrive/桌面/160726c3yzr9itzqu898wi.jpg')
rgb1_to_gray (Image, GrayImage)
binary_threshold(GrayImage, Region, 'max_separability', 'dark', UsedThreshold)
connection(Region, ConnectedRegions)
select_shape(ConnectedRegions, SelectedRegions, ['outer_radius','roundness','inner_radius'], 'and', [1100,0.8,0], [1300,1,100])
count_obj (SelectedRegions, Number)
if (Number >0)
    is_lens_found := true
    shape_trans (SelectedRegions, Lens, 'convex')
endif
***因為印刷不均勻所以內外印刷點 要用不同的條件擷取
***這只是一種思路 參數可能還要調整
***這個方法對於均勻印刷 可能會有問題! 可能需要判斷應用時機!  
difference(Region, SelectedRegions, RegionDifference)
closing_circle(RegionDifference, RegionClosing, 51.5)
opening_circle(RegionClosing, RegionOpening, 23.5)
shape_trans(RegionOpening, RegionTrans, 'convex')
difference(RegionTrans, RegionOpening, RegionDifference1)
opening_circle(RegionDifference1, RegionOpening1, 13.5)
connection(RegionOpening1, ConnectedRegions1)
select_shape_std(ConnectedRegions1, SelectedRegions1, 'max_area', 70)
reduce_domain(GrayImage, SelectedRegions1, ImageReduced)
binary_threshold(ImageReduced, inner_paint, 'max_separability', 'dark', UsedThreshold1)

***取外緣(可以用半徑建立一個圓形區域去分析 避開標記點)
closing_circle(RegionDifference, RegionClosing, 51.5)
opening_circle(RegionClosing, outer_paint, 140.5)

***合併內外
union2(outer_paint, inner_paint, RegionUnion)
fill_up_shape(RegionUnion, RegionFillUp, 'area', 1, 5000)
closing_circle(RegionFillUp, RegionClosing1, 63.5)
opening_circle(RegionClosing1, ink_area, 43.5)

shape_trans(ink_area, outter_shape, 'outer_circle')
fill_up(ink_area, RegionFillUp1)
difference(RegionFillUp1, ink_area, RegionDifference2)
shape_trans(RegionDifference2, inner_shape, 'outer_circle')
difference(outter_shape, inner_shape, paint_region)

2025-02-27 18 19 19.jpg
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

hankchang 发表于 2025-2-28 11:13:26 | 显示全部楼层
本帖最后由 hankchang 于 2025-2-28 17:30 编辑
Jescal0001 发表于 2025-2-27 16:17
感谢大神 目前还有一个问题是 我抓中间那块区域抓得不太准
你可以帮我看一下我的代码吗 谢谢

方法二
***使用FFT 低通濾波去除背景: 本方法應該可以解決方法一, 因背景差異所帶來的問題, 應可適用於各種背景狀況

dev_close_window()
dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
read_image (Image160726c3yzr9itzqu898wi, 'C:/Users/genel/OneDrive/桌面/160726c3yzr9itzqu898wi.jpg')
rgb1_to_gray(Image160726c3yzr9itzqu898wi, GrayImage)
get_image_size(GrayImage, Width, Height)
***截止頻率可用範圍很大 0.015~0.04
gen_lowpass (ImageLowpass, 0.04, 'none', 'dc_center', Width, Height)
fft_generic(GrayImage, ImageFFT, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')
convol_fft(ImageFFT, ImageLowpass, ImageConvol)
fft_generic(ImageConvol, ImageFFT1, 'from_freq', 1, 'sqrt', 'dc_center', 'byte')
***去除低通部分(刪去背景 無論亮暗)
sub_image(GrayImage, ImageFFT1, ImageSub, 1, 128)
***這樣可以降低背景亮暗不均的干擾
*binary_threshold(ImageSub, Region, 'max_separability', 'dark', UsedThreshold)

mean_image(ImageSub, ImageMean, 51, 51)
dyn_threshold(ImageSub, ImageMean, Region, 5, 'dark')
connection(Region, ConnectedRegions)
select_shape(ConnectedRegions, SelectedRegions, 'outer_radius', 'and', 1000, 2000)
smallest_circle(SelectedRegions, Row, Column, Radius)
gen_circle(Circle, Row, Column, Radius-80)
intersection(Region, Circle, RegionIntersection)
connection(RegionIntersection, ConnectedRegions1)
select_shape(ConnectedRegions1, SelectedRegions1, 'area', 'and', 50, 999999)
union1(SelectedRegions1, RegionUnion)
**
closing_circle(RegionUnion, RegionClosing, 90.5)
opening_circle(RegionClosing, RegionOpening, 50.5)
***取得外圓
shape_trans(RegionOpening, outer_circle, 'outer_circle')
difference(outer_circle, RegionOpening, raw_inner_part)
**取得光學區域
connection(raw_inner_part, ConnectedRegions2)
select_shape_std(ConnectedRegions2, inner_part, 'max_area', 70)
shape_trans(inner_part, optical_region, 'outer_circle')
***獲得環狀印刷區域
difference(outer_circle, optical_region, ink_region)
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表