DIP作业1 直方图均衡化 matlab

来源:互联网 发布:阿格里奇 知乎 编辑:程序博客网 时间:2024/05/20 17:27
% 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-255for 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    endendh_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.0function [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);    endendim_conv = uint8(im_conv);his_conv = histogram(im_conv);


0 0
原创粉丝点击