掩模Mask_一幅图进行抠图

http://www.cnblogs.com/skyfsm/p/6894685.html


                                               详解掩膜mask

对一幅图进行抠图操作


#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <std
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面的代码进行复杂化%高志远 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
07-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值