缺陷检测解决策略之三: 频域+空域

缺 陷 检 测 解 决 策 略 之 三 : 频 域 + 空 域 缺陷检测解决策略之三: 频域+空域 +

快速傅里叶变换
fft_generic (GrayImage, ImageFFT, ‘to_freq’, -1, ‘sqrt’, ‘dc_center’, ‘complex’)
快速反傅里叶变换
fft_generic (ImageFFT, ImageFFT1, ‘from_freq’, 1, ‘sqrt’, ‘dc_center’, ‘complex’)


1.傅里叶变换:从空间域转到频域
2.设计滤波,获得所需频段(在频域处理后,将目标和背景的区别度提高,再返回空间域去提出缺陷目标)
3.反傅里叶变换:从频域转到空间域


频域的作用:
1.去噪声
2.增强对比度,方便检测缺陷
3…


常用辅助缺陷检测算子

texture_laws (ImageReduced, ImageTexture, ‘el’, 2, 5)

calculate_lines_gauss_parameters (17, [25,3], Sigma, Low, High)
lines_gauss (ImageReduced, Lines, Sigma, Low, High, ‘dark’, ‘true’, ‘gaussian’, ‘true’)


cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)



频域变换:傅里叶变换、小波变换等
要懂得空间域的哪一个部分对应了什么频谱,就能比较好的掌握其应用
傅里叶变换的性质:
1.对称性
2.平移性
3.共轭性
4.周期性
频谱表示的灰度变化情况,就是梯度
如果频谱离中心越远,越亮,说明在这个方向上,变化越剧烈,即梯度越高


(频谱四周)高频的:变化剧烈的地方,往往是细节部分
(频谱中心部分)低频的:灰度值几乎不变的地方,往往是背景



傅里叶变换具有对称性,所以频谱图像一般是以图像中心为原点左上右下对称,右上左下对称
频谱一般是四个角,但是为了方便,放在了中心
频率图像中心一般是低频成分,从中心往外,频率逐渐增加。每一点亮度值越高表示这个频率特征很突出,亮点越多越亮表示该频率成分越多,一般都是吧图像中心设置成低频。
亮带越宽,表示涵盖的频谱越丰富,即变化的宽度范围大


滤波器
1.低通滤波器,中间低频过,四周高频过滤。反傅里叶变换以后,图像就会变的模糊,细节减少了
2.高通滤波器,中间低频过滤,四周高频过。反傅里叶变换以后,图像边缘被强化。(gen_highpass)
3.带通滤波器
4.高斯滤波器

* 高通滤波器,0.1表示大小,越大会让图像越锐利
gen_highpass (ImageHighpass, 0.1, 'none', 'dc_center', 512, 512)```

* 示例1
read_image (Image1, 'C:/Users/29939/Desktop/企业微信截图_16433303918073.png')
rgb1_to_gray (Image1, GrayImage)
zoom_image_size (GrayImage, ImageZoom, 512, 512, 'constant')
fft_generic (ImageZoom, ImageFFT1, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')
gen_highpass (ImageHighpass, 0.1, 'none', 'dc_center', 512, 512)
convol_fft (ImageFFT1, ImageHighpass, ImageConvol)
fft_image_inv (ImageConvol, ImageFFTInv)
* 示例2
read_image (Image1, 'C:/Users/29939/Desktop/企业微信截图_16433303918073.png')
rgb1_to_gray (Image1, GrayImage)
zoom_image_size (GrayImage, ImageZoom, 512, 512, 'constant')
fft_generic (ImageZoom, ImageFFT1, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')
gen_highpass (ImageHighpass, 0.1, 'none', 'dc_center', 512, 512)
convol_fft (ImageFFT1, ImageHighpass, ImageConvol)
fft_generic (ImageConvol, ImageFFT2, 'from_freq', 1, 'sqrt', 'dc_center', 'complex')


* 低通滤波器,0.1表示大小,越大会让图像模糊。和中值滤波一样的效果
gen_lowpass (ImageLowpass, 0.1, 'none', 'dc_center', 512, 512)
* 示例1:
read_image (Image1, 'C:/Users/29939/Desktop/企业微信截图_16433303918073.png')
rgb1_to_gray (Image1, GrayImage)
zoom_image_size (GrayImage, ImageZoom, 512, 512, 'constant')
fft_generic (ImageZoom, ImageFFT1, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')
gen_lowpass (ImageLowpass, 0.1, 'none', 'dc_center', 512, 512)
convol_fft (ImageFFT1, ImageLowpass, ImageConvol)
fft_generic (ImageConvol, ImageFFT2, 'from_freq', 1, 'sqrt', 'dc_center', 'complex')



高斯滤波器
Sigma1 := 10.0
gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'dc_center', Width, Height)
Sigma1 := 10.0
Sigma2 := 3.0
gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'dc_center', Width, Height)
gen_gauss_filter (GaussFilter2, Sigma2, Sigma2, 0.0, 'none', 'dc_center', Width, Height)
sub_image (GaussFilter1, GaussFilter2, Filter, 1, 0)

在这里插入图片描述

* 带通滤波器
gen_sin_bandpass (ImageBandpass, 0.4, 'none', 'rft', Width, Height)

频谱看法:
一看方向,表示在什么方向上发送变化
二看亮带的宽窄,越宽,表示变化的范围越光。
三看亮度,越亮表示变化越剧烈


三种频谱处理手法
1.draw/gen手画区域
paint_region:涂黑(区域到图像)
2.转成功率谱(power_real (ImageFFT2, ImageResult1)
3.滤波器

1.draw/gen手画区域

示例1:

* step1
read_image (Image, 'test7.png')
* step2
rgb1_to_gray (Image, GrayImage)
* step3
fft_image (GrayImage, ImageFFT4)
* step4
gen_rectangle1 (ROI_0, 8.28752, 3.48559, 156.42, 152.66)
gen_rectangle1 (TMP_Region, 7.65984, 164.617, 154.537, 313.223)
union2 (ROI_0, TMP_Region, ROI_0)
gen_rectangle1 (TMP_Region, 167.091, 2.91622, 320.245, 152.091)
union2 (ROI_0, TMP_Region, ROI_0)
gen_rectangle1 (TMP_Region, 168.974, 169.172, 318.989, 314.931)
union2 (ROI_0, TMP_Region, ROI_0)
* step5
paint_region (ROI_0, ImageFFT4, ImageResult, 0, 'fill')
* step6
fft_image_inv (ImageResult, ImageFFTInv)

示例2:(频域+空域)来检测特征

dev_get_window (WindowHandle)
read_image (Image1, 'C:/Users/29939/Desktop/企业微信截图_16433303918073.png')
rgb1_to_gray (Image1, GrayImage)
fft_image (GrayImage, ImageFFT)
gen_rectangle1 (ROI_0, 27.4359, 25.9474, 190.912, 261.505)
gen_rectangle1 (TMP_Region, 210.916, 276.316, 368.874, 522.453)
union2 (ROI_0, TMP_Region, ROI_0)
* step5
paint_region (ROI_0, ImageFFT, ImageResult, 0, 'fill')
* step6
fft_image_inv (ImageResult, ImageFFTInv)

dev_display (ImageFFTInv)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

* 傅里叶变换
fft_image (Image1, ImageFFT)
* 快速傅里叶变换
* dc_center:将频谱放在中心
* to_freq :空间域到频域
fft_generic (Image4, ImageFFT3, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')

示例1

决定方形区域内的灰度值,计算方形区域内的最大最小灰度的差,设置到每个图像点上
增强对比度,图像增强的一种
gray_range_rect (ImageFiltered, ImageResult, 10, 10)

dev_update_off ()
dev_close_window ()
* 读取图像
read_image (Image, 'plastics/plastics_01')
* 获取图像大小
get_image_size (Image, Width, Height)
* 窗口显示设置
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_color ('red')
* 优化傅里叶变换速度
optimize_rft_speed (Width, Height, 'standard')
* 参数设置
Sigma1 := 10.0
Sigma2 := 3.0
* 高斯滤波
gen_gauss_filter (GaussFilter1, Sigma1, Sigma1, 0.0, 'none', 'rft', Width, Height)
* 高斯滤波
gen_gauss_filter (GaussFilter2, Sigma2, Sigma2, 0.0, 'none', 'rft', Width, Height)
* 滤波相减
sub_image (GaussFilter1, GaussFilter2, Filter, 1, 0)
* 遍历
NumImages := 11
for Index := 1 to NumImages by 1
    * 读取图像
    read_image (Image, 'plastics/plastics_' + Index$'02')
    * rgb转灰度
    rgb1_to_gray (Image, Image)
    * 傅里叶变换
    rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
    * 高斯滤波
    convol_fft (ImageFFT, Filter, ImageConvol)
    * 反傅里叶变换
    rft_generic (ImageConvol, ImageFiltered, 'from_freq', 'n', 'real', Width)
    * 决定方形区域内的灰度值,计算方形区域内的最大最小灰度的差,设置到每个图像点上
    * 增强对比度,图像增强的一种
    gray_range_rect (ImageFiltered, ImageResult, 10, 10)
    * 获取灰度的最大值、最小值、和范围(最大值-最小值)
    min_max_gray (ImageResult, ImageResult, 0, Min, Max, Range)
    * 阈值分割
    threshold (ImageResult, RegionDynThresh, max([5.55,Max * 0.8]), 255)
    * 连通
    connection (RegionDynThresh, ConnectedRegions)
    * 特征选取
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 4, 99999)
    * 合并区域
    union1 (SelectedRegions, RegionUnion)
    * 开运算
    closing_circle (RegionUnion, RegionClosing, 10)
    * 连通
    connection (RegionClosing, ConnectedRegions1)
    * 特征选取
    select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 10, 99999)
    * 获取面积和区域中心点
    area_center (SelectedRegions1, Area, Row, Column)
    * 显示图像
    dev_display (Image)
    * 遍历所有区域
    Number := |Area|
    if (Number)
        * 生产轮廓
        gen_circle_contour_xld (ContCircle, Row, Column, gen_tuple_const(Number,30), gen_tuple_const(Number,0), gen_tuple_const(Number,rad(360)), 'positive', 1)
        * 设置显示结果
        ResultMessage := ['Not OK',Number + ' defect(s) found']
        Color := ['red','black']
        dev_display (ContCircle)
    else
        ResultMessage := 'OK'
        Color := 'forest green'
    endif
    * 显示结果信息
    disp_message (WindowHandle, ResultMessage, 'window', 12, 12, Color, 'true')
    if (Index != NumImages)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor


在这里插入图片描述

示例2:频域+空域+差分

* this example shows how to detect mura defects
* in blurred images
* 
dev_close_window ()
dev_update_off ()
Path := 'lcd/mura_defects_blur_'
* 读取图像
read_image (Image, Path + '01')
* 获取图像大小
get_image_size (Image, Width, Height)
* 窗口显示设置
dev_open_window_fit_size (0, 0, Width, Height, 640, 480, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_color ('red')
ScaleFactor := 0.4
* 计算找线参数
calculate_lines_gauss_parameters (17, [25,3], Sigma, Low, High)
* 遍历
for f := 1 to 3 by 1
    * 读取图像
    read_image (Image, Path + f$'.2i')
    * 分解通道
    decompose3 (Image, R, G, B)
    * 快速傅里叶变换
    rft_generic (B, ImageFFT, 'to_freq', 'none', 'complex', Width)
    * 高斯滤波
    gen_gauss_filter (ImageGauss, 100, 100, 0, 'n', 'rft', Width, Height)
    * 卷积
    convol_fft (ImageFFT, ImageGauss, ImageConvol)
    * 反傅里叶变换
    rft_generic (ImageConvol, ImageFFT1, 'from_freq', 'none', 'byte', Width)
    * 图像相减
    sub_image (B, ImageFFT1, ImageSub, 2, 100)
    * 缩放图片
    zoom_image_factor (ImageSub, ImageZoomed, ScaleFactor, ScaleFactor, 'constant')
    * 获取图像区域
    get_domain (ImageZoomed, Domain)
    * 腐蚀
    erosion_rectangle1 (Domain, RegionErosion, 7, 7)
    * 获取图像
    reduce_domain (ImageZoomed, RegionErosion, ImageReduced)
    * 找线算子
    lines_gauss (ImageReduced, Lines, Sigma, Low, High, 'dark', 'true', 'gaussian', 'true')
    * 生产几何变换矩阵
    hom_mat2d_identity (HomMat2DIdentity)
    * 
    hom_mat2d_scale_local (HomMat2DIdentity, 1 / ScaleFactor, 1 / ScaleFactor, HomMat2DScale)
    * 仿射变换
    affine_trans_contour_xld (Lines, Defects, HomMat2DScale)
    * 
    dev_display (Image)
    dev_display (Defects)
    if (f < 3)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor

在这里插入图片描述

示例3: 频域+差分+空域(blob分析+特征)

*  estimate_background_illumination (B, ImageFFT1)函数:
get_image_size (Image, Width, Height)
rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
gen_gauss_filter (ImageGauss, 50, 50, 0, 'n', 'rft', Width, Height)
convol_fft (ImageFFT, ImageGauss, ImageConvol)
rft_generic (ImageConvol, IlluminationImage, 'from_freq', 'none', 'byte', Width)
return ()
* 关闭窗口
dev_close_window ()
dev_update_off ()
Path := 'lcd/mura_defects_texture_'
* 读取图片
read_image (Image, Path + '01')
* 获取图像大小
get_image_size (Image, Width, Height)
* 设置窗体显示
dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_color ('red')
for F := 1 to 2 by 1
    * 读取图像
    read_image (Image, Path + F$'.2i')
    * 分解成三个通道
    decompose3 (Image, R, G, B)
    * 增强缺陷显示
    estimate_background_illumination (B, ImageFFT1)
    * 图像相减
    sub_image (B, ImageFFT1, ImageSub, 2, 100)
    * 中值滤波
    median_image (ImageSub, ImageMedian, 'circle', 9, 'mirrored')
    * 图像分割
    watersheds_threshold (ImageMedian, Basins, 20)
    * 计算共现矩阵并导出其灰度值特征。
    cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
    * 计算掩膜
    Mask := Energy [<=] 0.05
    * 选择缺陷
    select_mask_obj (Basins, Defects, Mask)
    * 图像显示
    dev_display (Image)
    dev_display (Defects)
    * 计算缺陷个数
    count_obj (Defects, NDefects)
    * 显示结果信息
    disp_message (WindowHandle, NDefects + ' \'mura\' defects detected', 'window', 12, 12, 'red', 'true')
    if (F < 2)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor

在这里插入图片描述

纯空间域的做一个对比

mean_image (Image, ImageMean, 7, 7)
dyn_threshold (Image, ImageMean, DarkPixels, 5, 'dark')
* This programm shows the extraction of surface scratches via
* local thresholding and morphological post-processing
* 
dev_update_off ()
dev_close_window ()
* 
* Step 1: Acquire image
* 
read_image (Image, 'surface_scratch')
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Width, WindowID)
set_display_font (WindowID, 16, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (4)
dev_display (Image)
Message := 'This program shows the extraction of'
Message[1] := 'surface scratches via local thresholding'
Message[2] := 'and morphological post-processing'
disp_message (WindowID, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowID, 'black', 'true')
stop ()
* 
* Step 2: Segment image
* 
* Using a local threshold
mean_image (Image, ImageMean, 7, 7)
dyn_threshold (Image, ImageMean, DarkPixels, 5, 'dark')
* 
* Extract connected components
connection (DarkPixels, ConnectedRegions)
dev_set_colored (12)
dev_display (Image)
dev_display (ConnectedRegions)
Message := 'Connected components after image segmentation'
Message[1] := 'using a local threshold.'
disp_message (WindowID, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowID, 'black', 'true')
stop ()
* 
* Step 3: Process regions
* 
* Select large regions
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 1000)
dev_display (Image)
dev_display (SelectedRegions)
disp_message (WindowID, 'Large Regions', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowID, 'black', 'true')
stop ()
* 
* Visualize fractioned scratch
open_zoom_window (0, round(Width / 2), 2, 303, 137, 496, 3, WindowHandleZoom)
dev_set_color ('blue')
dev_display (Image)
dev_display (SelectedRegions)
set_display_font (WindowHandleZoom, 16, 'mono', 'true', 'false')
disp_message (WindowHandleZoom, 'Fractioned scratches', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandleZoom, 'black', 'true')
stop ()
* 
* Merge fractioned scratches via morphology
union1 (SelectedRegions, RegionUnion)
dilation_circle (RegionUnion, RegionDilation, 3.5)
dev_display (Image)
dev_display (RegionDilation)
Message := 'Region of the scratches after dilation'
disp_message (WindowHandleZoom, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandleZoom, 'black', 'true')
stop ()
skeleton (RegionDilation, Skeleton)
connection (Skeleton, Errors)
dev_set_colored (12)
dev_display (Image)
dev_display (Errors)
Message := 'Fractioned scratches merged via morphology'
disp_message (WindowHandleZoom, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandleZoom, 'black', 'true')
stop ()
* 
* Distinguish small and large scratches
close_zoom_window (WindowHandleZoom, Width, Height)
select_shape (Errors, Scratches, 'area', 'and', 50, 10000)
select_shape (Errors, Dots, 'area', 'and', 1, 50)
dev_display (Image)
dev_set_color ('red')
dev_display (Scratches)
dev_set_color ('blue')
dev_display (Dots)
Message := 'Extracted surface scratches'
Message[1] := 'Not categorized as scratches'
disp_message (WindowID, Message, 'window', 440, 310, ['red','blue'], 'true')

在这里插入图片描述

示例4:频域+空域

* 窗口设置
dev_update_off ()
dev_close_window ()
* 读取图像
read_image (Image, 'surface_scratch')
* 图像倒置
invert_image (Image, ImageInverted)
* 获取图像大小
get_image_size (Image, Width, Height)
* 窗口显示设置
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
* 带通滤波器
gen_sin_bandpass (ImageBandpass, 0.4, 'none', 'rft', Width, Height)
* 傅里叶变换
rft_generic (ImageInverted, ImageFFT, 'to_freq', 'none', 'complex', Width)
* 利用带通滤波器对傅里叶变换图像进行卷积
convol_fft (ImageFFT, ImageBandpass, ImageConvol)
* 反傅里叶变换(频域转空间域)
rft_generic (ImageConvol, Lines, 'from_freq', 'n', 'byte', Width)
* 图像分割
threshold (Lines, Region, 5, 255)
* 连通
connection (Region, ConnectedRegions)
* 选取特征
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5, 5000)
* 膨胀
dilation_circle (SelectedRegions, RegionDilation, 5.5)
* 连结
union1 (RegionDilation, RegionUnion)
* 获取区域图像
reduce_domain (Image, RegionUnion, ImageReduced)
* 找线算子
lines_gauss (ImageReduced, LinesXLD, 0.8, 3, 5, 'dark', 'false', 'bar-shaped', 'false')
* 合并轮廓
union_collinear_contours_xld (LinesXLD, UnionContours, 40, 3, 3, 0.2, 'attr_keep')
* 根据特征选取轮廓
select_shape_xld (UnionContours, SelectedXLD, 'contlength', 'and', 15, 1000)
* 生成轮廓
gen_region_contour_xld (SelectedXLD, RegionXLD, 'filled')
* 合并
union1 (RegionXLD, RegionUnion)
* 膨胀
dilation_circle (RegionUnion, RegionScratches, 10.5)
* 显示结果
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_colored (12)
dev_display (Image)
dev_display (RegionScratches)

在这里插入图片描述

示例5:频域+差分+空域

* This program shows how to separate foreground information
* from a disturbing background texture by filtering in the
* frequency domain.
* First, the image is fourier transformed in order to obtain
* its frequency spectrum. Then, we detect the frequency peaks
* corresponding to the disturbing background texture in the
* frequency spectrum. Afterwards, a filter which eliminates those
* frequencies is built and applied to the spectrum. By applying
* the inverse fourier transform to the filtered spectrum, we
* obtain a filtered image from which the disturbing background
* texture was removed.
* 
dev_update_off ()
dev_close_window ()
Scale := [1.0,.65]
MinGray := [50,100]
for Index := 0 to 1 by 1
    * 
    * Read and display the image
    read_image (Image, 'plan_' + (Index + 1)$'02')
    get_image_size (Image, Width, Height)
    dev_open_window (0, 0, Width * Scale[Index], Height * Scale[Index], 'black', WindowHandle)
    set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
    dev_set_part (0, 0, Height - 1, Width - 1)
    dev_display (Image)
    disp_message (WindowHandle, 'Original image', 'window', 12, 12, 'black', 'true')
    * 
    * Perform fft and display spectrum
    optimize_fft_speed (Width, Height, 'standard')
    * 
    * We used 'fft_generic' 'sqrt' and 'dc_center' mainly
    * for visualization purposes.
    * To speed up the program, rft_generic should be used;
    * but of course, the peak detection algorithm has to be
    * adjusted in this case.
    fft_generic (Image, ImageFFT, 'to_freq', -1, 'sqrt', 'dc_center', 'complex')
    dev_open_window (0, Width * Scale[Index] + 7, Width * Scale[Index], Height * Scale[Index], 'black', WindowHandle1)
    dev_set_color ('red')
    dev_set_draw ('margin')
    set_display_font (WindowHandle1, 14, 'mono', 'true', 'false')
    dev_set_part (0, 0, Height - 1, Width - 1)
    dev_display (ImageFFT)
    disp_message (WindowHandle1, 'Fourier spectrum', 'window', 12, 12, 'black', 'true')
    disp_cont_message (WindowHandle1, 'black', 'true')
    stop ()
    * 
    * Detect the eight most significant peaks in the spectrum
    power_real (ImageFFT, PowerSpectrum)
    binomial_filter (PowerSpectrum, ImageSmooth, 9, 9)
    threshold (ImageSmooth, Region, MinGray[Index], 100000)
    connection (Region, ConnectedRegions)
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5, 200)
    union1 (SelectedRegions, RegionUnion)
    reduce_domain (ImageSmooth, RegionUnion, ImageReduced)
    local_max (ImageReduced, LocalMaxima)
    * 
    * Next, detect peaks one octave higher, i.e., at twice
    * the frequency of the most significant peaks
    shape_trans (LocalMaxima, RegionTrans, 'convex')
    * Construct ROI band at twice the frequency
    hom_mat2d_identity (HomMat2DIdentity)
    hom_mat2d_scale (HomMat2DIdentity, 2.1, 2.1, Height / 2, Width / 2, HomMat2DScale)
    affine_trans_region (RegionTrans, RegionTrans1, HomMat2DScale, 'nearest_neighbor')
    hom_mat2d_scale (HomMat2DIdentity, 1.9, 1.9, Height / 2, Width / 2, HomMat2DScale)
    affine_trans_region (RegionTrans, RegionTrans2, HomMat2DScale, 'nearest_neighbor')
    difference (RegionTrans1, RegionTrans2, RegionDifference)
    * Extract the peaks at twice the frequency
    reduce_domain (ImageSmooth, RegionDifference, ImageReduced)
    threshold (ImageReduced, Region, 15, 100000)
    reduce_domain (ImageSmooth, Region, ImageReduced)
    local_max (ImageReduced, LocalMaxima2)
    * 
    * Merge the peaks of both octaves and enlarge them to
    * integrate the relevant frequencies into the filter
    union2 (LocalMaxima, LocalMaxima2, RegionUnion)
    dilation_circle (RegionUnion, RegionDilation, 15.5)
    paint_region (RegionDilation, ImageFFT, ImageFFTFiltered, 0, 'fill')
    dev_display (ImageFFT)
    dev_display (RegionDilation)
    disp_message (WindowHandle1, 'Frequencies of the\nbackground texture', 'window', 12, 12, 'black', 'true')
    disp_cont_message (WindowHandle1, 'black', 'true')
    stop ()
    * 
    * Apply the filter and display the results
    fft_generic (ImageFFTFiltered, ImageFiltered, 'from_freq', 1, 'sqrt', 'dc_center', 'byte')
    dev_display (ImageFiltered)
    disp_message (WindowHandle1, 'Filtered image', 'window', 12, 12, 'black', 'true')
    * 
    dev_open_window (0, 2 * (Width * Scale[Index]) + 14, Width * Scale[Index], Height * Scale[Index], 'black', WindowHandle2)
    set_display_font (WindowHandle2, 14, 'mono', 'true', 'false')
    dev_set_part (0, 0, Height - 1, Width - 1)
    sub_image (Image, ImageFiltered, ImageTexture, 1, 128)
    dev_display (ImageTexture)
    disp_message (WindowHandle2, 'Removed texture', 'window', 12, 12, 'black', 'true')
    if (Index < 1)
        disp_cont_message (WindowHandle2, 'black', 'true')
        stop ()
        dev_close_window ()
        dev_close_window ()
        dev_close_window ()
    endif
endfor

在这里插入图片描述
在这里插入图片描述

***
* 用导向滤波获取纹理
***

* 设置窗口
dev_update_off ()
dev_close_window ()
NumImages := 2
for Index := 1 to NumImages by 1
    * 读取图像
    read_image (Image, 'plan_' + Index$'02')
    * 设置窗口显示
    dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
    set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
    dev_display (Image)
    disp_message (WindowHandle, 'Original image', 'window', 12, 12, 'black', 'true')
    * 获取窗口的大小和位置
    get_window_extents (WindowHandle, Row, Column, Width, Height)
    * 设置窗口显示
    dev_open_window_fit_image (Image, 0, Width + 8, -1, -1, WindowHandle1)
    set_display_font (WindowHandle1, 14, 'mono', 'true', 'false')
    dev_open_window_fit_image (Image, 0, 2 * Width + 16, -1, -1, WindowHandle2)
    set_display_font (WindowHandle2, 14, 'mono', 'true', 'false')
    * 生成一个灰度值为0的图像
    gen_image_proto (Image, ImageStructure, 0)
    for Index1 := 1 to 3 by 1
        * 导向滤波
        guided_filter (Image, ImageStructure, ImageStructure, 1.5, 15)
    endfor
    * 图像相减获取纹理
    sub_image (Image, ImageStructure, ImageTexture, 1, 128)
    * 显示结果
    dev_set_window (WindowHandle)
    dev_display (Image)
    disp_message (WindowHandle, 'Original image ' + Index, 'window', 12, 12, 'black', 'true')
    dev_set_window (WindowHandle1)
    dev_display (ImageStructure)
    disp_message (WindowHandle1, 'Filtered image', 'window', 12, 12, 'black', 'true')
    dev_set_window (WindowHandle2)
    dev_display (ImageTexture)
    disp_message (WindowHandle2, 'Extracted texture', 'window', 12, 12, 'black', 'true')
    if (Index < NumImages)
        disp_continue_message (WindowHandle2, 'black', 'true')
        stop ()
        dev_close_window ()
        dev_close_window ()
        dev_close_window ()
    endif
endfor

在这里插入图片描述

补充


min_max_gray(Regions, Image : : Percent : Min, Max, Range)

Percent (input_control)  number → (real / integer)
Percentage below (above) the absolute maximum (minimum).
Default value: 0
Suggested values: 0, 1, 2, 5, 7, 10, 15, 20, 30, 40, 50
Restriction: 0 <= Percent && Percent <= 50
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值