admin管理员组

文章数量:1660165

以下代码是HALCON图像处理软件的脚本,其主要作用是检测图像中的“mura”缺陷

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)
* defects are characterized by dark patches. Hence, by substracting the
* estimated background illumination from the original image the
* defects become more apparent
estimate_background_illumination (B, ImageFFT1)
sub_image (B, ImageFFT1, ImageSub, 2, 100)
* median filter smooths out the fine texture, simplifying the following
* segmentation and final detection of defects
median_image (ImageSub, ImageMedian, ‘circle’, 9, ‘mirrored’)
watersheds_threshold (ImageMedian, Basins, 20)
* dark patches corresponding to defects have a very low energy
cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
tuple_find (sgn(Energy - 0.05), -1, Indices)
select_obj (Basins, Defects, Indices + 1)
*
dev_display (Image)
dev_display (Defects)
count_obj (Defects, NDefects)
disp_message (WindowHandle, NDefects + ’ ‘mura’ defects detected’, ‘window’, -1, -1, ‘red’, ‘true’)
if (f < 2)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
endif
endfor

代码的主要步骤和功能解释如下:

初始化和窗口设置:

dev_close_window():关闭所有打开的窗口。
dev_update_off():关闭图像更新,以提高处理速度。
Path := ‘lcd/mura_defects_texture_’:设置图像文件的路径。
read_image(Image, Path + ‘1’):读取编号为1的图像。
get_image_size(Image, Width, Height):获取图像的宽度和高度。
dev_open_window(, , 640, 480, ‘black’, WindowHandle):打开一个640x480像素的黑色背景窗口。
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:循环处理两张图像,编号为1和2。
图像读取和颜色分解:

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, , Energy, Correlation, Homogeneity, Contrast):计算图像的特征,如能量、相关性、均匀性和对比度。
tuple_find(sgn(Energy - .5), -1, Indices):找到能量值低于.5的特征索引。
select_obj(Basins, Defects, Indices + 1):根据找到的索引选择缺陷区域。
结果显示:

dev_display(Image):显示原始图像。
dev_display(Defects):显示检测到的缺陷区域。
count_obj(Defects, NDefects):计算检测到的缺陷数量。
disp_message(WindowHandle, NDefects + ’ ‘mura’ defects detected’, ‘window’, -1, -1, ‘red’, ‘true’):在窗口中显示检测到的缺陷数量。
循环控制:

如果当前处理的图像不是最后一张,显示继续消息并暂停,直到用户决定继续。
这段代码通过估计背景照明、中值滤波、阈值分割和特征计算等步骤,实现了自动化的图像缺陷检测流程。这对于提高液晶显示屏等电子设备的质量控制非常有用。

本文标签: 纹理可能出现液晶显示屏过程中不均匀