DIP作业1 直方图均衡化 matlab

% Function: Calculate the normalized histogram of an image.
% Prameter: 
%     Input:
%         im: gray image with gray level 0-255(must be gray image)
%     Output:
%         h_nor: normalized histogram(possibilities)
% Author: ZhouJingjin
% Version: 1.0
    
function h_nor = histogram(im)
[M,N] = size(im);
h = zeros(1,256);                               %gray level: 0-255
for i = 1:M
    for j = 1:N
        h(im(i,j)+1) = h(im(i,j)+1) + 1;        %calculate the number of pixels for each gray level
    end
end
h_nor = h / (M*N);                              %normalized histogram
% Function: Implement the histogram equalization technique to an image.
% Prameter: 
%     Input:
%         im: Gray image with gray level 0-255(must be gray image)
%     Output:
%         im_conv: Enhanced image
%         his_conv: normalized histogram(possibilities) of the enhanced
%         image:use for plotting the histogram-equalization(s_k versus r_k)
%         conv_table:
% Author: ZhouJingjin
% Version: 1.0

function [his_conv, im_conv, conv_table] = his_equ(im)
his = histogram(im);
cdf = cumsum(his);
conv_table = round(cdf * 255);
[M,N] = size(im);
im_conv = zeros(M,N);
for i = 1:M
    for j = 1:N
        im_conv(i,j) = conv_table(im(i,j) + 1);
    end
end
im_conv = uint8(im_conv);
his_conv = histogram(im_conv);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值