下面的代码进行复杂化%高志远 2220202262 % 读取图像 img = imread('GZY.jpg'); % 转换为灰度图像 grayImg = rgb2gray(img); Img = img; % 设置参数 width = size(grayImg, 2); height = size(grayImg, 1); smooth_type = 'SMOOTH_GS'; smooth_mask_width = 4; smooth_mask_height = 4; gaussian_sigma = 1; k = 1.5; % 应用Unsharp Masking算法 dst_orginal = UnsharpMasking(double(Img), width, height, smooth_type, smooth_mask_width, smooth_mask_height, gaussian_sigma, k); dst = UnsharpMasking(double(grayImg), width, height, smooth_type, smooth_mask_width, smooth_mask_height, gaussian_sigma, k); % 显示原始图像和处理后的图像 figure; subplot(2, 2, 1); imshow(Img); title('原始图像'); subplot(2, 2, 4); imshow(uint8(dst)); title('处理后的图像'); subplot(2,2,3); imshow(uint8(dst_orginal)); title('灰度处理后'); subplot(2,2,2); imshow(grayImg); title('Unsharp Masking'); function dst = UnsharpMasking(src, width, height, smooth_type, smooth_mask_width, smooth_mask_height, gaussian_sigma, k) temp = zeros(width, height); switch smooth_type case 'SMOOTH_GS' temp = GaussianFilter(src, smooth_mask_width, smooth_mask_height, gaussian_sigma); case 'SMOOTH_M' temp = MeanFilter(src, smooth_mask_width, smooth_mask_height); otherwise error('Invalid smooth_type'); end % 计算差值图像 dst = src - temp; % 缩放差值图像 dst = dst * k; % 添加差值图像到原始图像 dst = src + dst; end function smoothed = GaussianFilter(src, mask_width, mask_height, sigma) % 创建高斯滤波掩模 mask = fspecial('gaussian', [mask_width, mask_height], sigma); % 进行滤波操作 smoothed = imfilter(src, mask); end function smoothed = MeanFilter(src, mask_width, mask_height) % 创建均值滤波掩模 mask = ones(mask_width, mask_height) / (mask_width * mask_height); % 进行滤波操作 smoothed = imfilter(src, mask); end
时间: 2024-04-09 10:31:39 浏览: 15
您提供的代码已经进行了复杂化,增加了一些参数和函数。这段代码实现了钝化蒙版(USM)效果并对图像进行了处理。
代码中的`UnsharpMasking`函数实现了钝化蒙版算法,根据指定的参数进行图像处理。`GaussianFilter`函数和`MeanFilter`函数分别实现了高斯滤波和均值滤波,用于平滑图像。
最后,代码通过调用`UnsharpMasking`函数对原始图像和灰度图像进行处理,并显示处理后的图像。
请注意,这段代码仍然是一个示例,可能需要根据实际情况进行调整和优化。根据您的需求,您可以根据自己的需要进行参数设置和函数调用。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)