请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 7658|回复: 0

FFT变换去除图像背景纹理

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 2018-12-1 23:27:25 | 显示全部楼层 |阅读模式
代码如下:
  1. dev_update_off ()
  2. dev_set_draw('margin')
  3. Scale := [1.0,.65]
  4. MinGray := [55,100]
  5. * Read and display the image
  6. read_image (Image, 'C:/Users/ysw/Desktop/2.jpg')
  7. count_channels(Image, Channels)
  8. if(Channels>1)
  9.     rgb1_to_gray(Image, Image)
  10. endif
  11. get_image_size (Image, Width, Height)
  12. dev_set_part (0, 0, Height - 1, Width - 1)
  13. dev_display (Image)
  14. *
  15. * Perform fft and display spectrum
  16. optimize_fft_speed (Width, Height, 'standard')
  17. *
  18. fft_generic (Image, ImageFFT, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')
  19. dev_set_color ('red')
  20. dev_display (ImageFFT)
  21. *
  22. * Detect the eight most significant peaks in the spectrum
  23. power_real (ImageFFT, PowerSpectrum)
  24. binomial_filter (PowerSpectrum, ImageSmooth, 9, 9)
  25. threshold (ImageSmooth, Region, MinGray[0], 100000)
  26. connection (Region, ConnectedRegions)
  27. select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 3, 200)
  28. union1 (SelectedRegions, RegionUnion)
  29. reduce_domain (ImageSmooth, RegionUnion, ImageReduced)
  30. local_max (ImageReduced, LocalMaxima)
  31. *
  32. * Next, detect peaks one octave higher, i.e., at twice
  33. * the frequency of the most significant peaks
  34. shape_trans (LocalMaxima, RegionTrans, 'convex')
  35. * Construct ROI band at twice the frequency
  36. hom_mat2d_identity (HomMat2DIdentity)
  37. hom_mat2d_scale (HomMat2DIdentity, 1.5, 1.5, Height / 2, Width / 2, HomMat2DScale)
  38. affine_trans_region (RegionTrans, RegionTrans1, HomMat2DScale, 'nearest_neighbor')
  39. hom_mat2d_scale (HomMat2DIdentity, 1.3, 1.3, Height / 2, Width / 2, HomMat2DScale)
  40. affine_trans_region (RegionTrans, RegionTrans2, HomMat2DScale, 'nearest_neighbor')
  41. difference (RegionTrans1, RegionTrans2, RegionDifference)
  42. * Extract the peaks at twice the frequency
  43. reduce_domain (ImageSmooth, RegionDifference, ImageReduced)
  44. threshold (ImageReduced, Region, 16, 100000)
  45. reduce_domain (ImageSmooth, Region, ImageReduced)
  46. local_max (ImageReduced, LocalMaxima2)
  47. *
  48. * Merge the peaks of both octaves and enlarge them to
  49. * integrate the relevant frequencies into the filter
  50. union2 (LocalMaxima, LocalMaxima2, RegionUnion)
  51. dilation_circle (RegionUnion, RegionDilation, 15.5)
  52. paint_region (RegionDilation, ImageFFT, ImageFFTFiltered, 0, 'fill')
  53. dev_display (ImageFFT)
  54. dev_display (RegionDilation)
  55. *
  56. * Apply the filter and display the results
  57. fft_generic (ImageFFTFiltered, ImageFiltered, 'from_freq', 1, 'sqrt', 'dc_center', 'byte')
  58. sub_image (Image, ImageFiltered, ImageTexture, 1, 128)
  59. dev_display (ImageTexture)
复制代码

(1)关键在于频率成分的选取;规则的纹理,均为低频成分,去掉低频成分即可。
(2)此代码中,关键点在于上、下两个频域成分的去除。

参考链接:https://pan.baidu.com/s/1RpiNyfULyjx7om_ta1LYzQ

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

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

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-28 19:12 , Processed in 0.192327 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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