数字图像处理实验之平滑线性滤波应用

代码如下:
主函数:

% 输入图像
img_1 = imread('Fig0334(a)(hubble-original).tif');
[r, c] = size(img_1);
% 滤波器模板
m = 15;

% 作用看我上一篇博客
img_1s = m_10_Smooth_create_img(img_1, r, c, m - 1);
img_2 = m_10_Smooth_process_img(img_1s, r, c, m);

% 找到图像中的最大灰度级
max_level = m_11_Smooth_Apply_find_max_level(img_2);
% 阈值
threshold = double(max_level) * 0.25;
% 阈值处理
img_3 = m_11_Smooth_Apply_threshold_process(img_2, threshold);

subplot(131), imshow(img_1);
subplot(132), imshow(img_2);
subplot(133), imshow(img_3);

m_11_Smooth_Apply_find_max_level.m 代码:

function level = m_11_Smooth_Apply_find_max_level(img)
% 该函数返回一张图像的最高灰度值

[r, c] = size(img);
level = 0;
for x = 1 : r
    for y = 1 : c
        if img(x, y) > level
            level = img(x, y);
        end
    end
end

end

m_11_Smooth_Apply_threshold_process.m 代码:

function img_1 = m_11_Smooth_Apply_threshold_process(img_1, threshold)
% 用threshold阈值,处理img_1

[r, c] = size(img_1);
img_1 = double(img_1);

for x = 1 : r
    for y = 1 : c
        if img_1(x, y) >= threshold
            img_1(x, y) = 1;
        else
            img_1(x, y) = 0;
        end
    end
end

end

实验结果如下:
实验结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值