一、定义
空间域:对像素的灰度处理
频域:傅里叶变换和小波变换,将空间域的信号拆分为不同频段的信号,将像素图像转换为频谱图。
频域检测缺陷的思路是先从空间域到频域,在频域中进行适当滤波,选择自己想要的频段,然后再返回到空间域中去。
二、处理算子:
fft_image(): 快速傅里叶变化,频谱原点在中心 空间域到频域
fif_image_inv(); 频域到空间域
fft_generic(): 参数可选在中心还是四个角上
rft_generic() 原点在四个角上
fft_generic(Image : ImageFFT : Direction, Exponent, Norm, Mode, ResultType : )
参数:
Image :输入图像
ImageFFT :频谱图
Direction:转换方向, ‘from_freq’,:从频谱图转到像素图 ‘to_freq’:从像素图到频谱图。
Exponent:Sign of the exponent.:1或-1,来回转换是分别填1,-1,若一致则图像为镜像。
Norm:归一化因子,List of values: ‘n’, ‘none’, ‘sqrt’;
'n’为这c=MN(图像宽高),图像会暗;‘none’:不使用,中;c; ‘sqrt’:c=sqrt(Mn),亮。
ResultType :图像数据类型,空间转频谱,只能选复数形式:compiex.
三、如何查看频谱图(信息包含:相位、频率高低,频段的含量):
1.每一点不是像素点,而是表示不同频率或频段,而且频谱图的中心为低频,从中心向四周逐渐增高,有时频谱中心不在窗口的中心。
2.频谱图的上下左右对称。
3.频谱图中每一点的亮度表示该频段的振幅(及灰度的变换程度),如果亮点有一定的宽度,说明这一点频率的含量比较丰富。
4.在频谱图中某个方向有亮点或亮线,说明该方向有灰度变化剧烈的边。
四、处理滤波器算子
gen_std_bandpass,
gen_sin_bandpass,
gen_gauss_filter,
gen_mean_filter,
gen_derivative_filter,
gen_bandpass,
gen_bandfilter,
低通滤波:gen_lowpass();
高通滤波:gen_highpass();
频谱图滤波算子:convol_fft(ImageFFT, ImageFilter : ImageConvol : : )
五、案例
* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('./plastics', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])
* Image Acquisition 01: Do something
get_image_size (Image, Width, Height)
rgb1_to_gray (Image, GrayImage)
*傅里叶变换转频域
fft_generic (GrayImage, ImageFFT, 'to_freq', -1, 'n', 'dc_center', 'complex')
*使用高斯滤波器做差分,弱化背景,增强缺陷
gen_gauss_filter (ImageGauss, 15, 15, 0, 'none', 'dc_center', Width, Height)
gen_gauss_filter (ImageGauss1, 3, 3, 0, 'none', 'dc_center', Width, Height)
sub_image (ImageGauss1, ImageGauss, ImageSub, 1, 128)
*对频谱图滤波
convol_fft (ImageFFT, ImageSub, ImageConvol)
*转换为空间域
fft_generic (ImageConvol, ImageFFT1, 'from_freq', 1, 'n', 'dc_center', 'real')
*Bold分析
*灰度增强处理
rgb1_to_gray (ImageFFT1, GrayImage)
gray_range_rect (GrayImage, ImageResult,9, 9)
min_max_gray (ImageResult, ImageResult, 0, Min, Max, Range)
fast_threshold (ImageResult, Region, max2(0.055,Max*0.85), 255, 5)
connection (Region, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions, 'area', 'and', 10, 99999)
union1 (SelectedRegions, RegionUnion)
closing_circle (RegionUnion, RegionClosing, 5)
connection (RegionClosing, ConnectedRegions)
area_center (ConnectedRegions, Area, Row, Column)
count_obj (ConnectedRegions, Number)
dev_display (Image)
if (Number>0)
dev_display (Region)
tuple_gen_const (Number, 20, R)
tuple_gen_const (Number, 0,PHIS)
tuple_gen_const (Number,rad(360),PHIE)
gen_circle_contour_xld (ContCircle, Row, Column, R, PHIS, PHIE, 'positive', 1)
dev_display (ContCircle)
disp_message (WindowHandle, 'NG', 'window', 12, 12, 'red', 'true')
else
disp_message (WindowHandle, 'OK', 'window', 12, 12, 'green', 'true')
endif
stop ()
endfor
效果图: