Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please complete the provided Matlab code to implement Histogram equalization. Pl

ID: 2248723 • Letter: P

Question

Please complete the provided Matlab code to implement Histogram equalization.
Please use the follow program to test your function.

J is output of the histogram equalization function provided by Matlab. Please compare your output and Matlab’s output.

function OutIm = HistogramEq(InIm)

HistogramEq Code:

% Input:
% InIm - input image
%
% Output:
% OutIm - output image
%

%%%%%%%%
%%%%%%%%

% get the size of input image;
[row, col] = size(InIm);
% initalize the histogram array;
H = zeros(1,256);
% initalize the output image;
OutIm = uint8(zeros(row, col));

% Step 1: computer histogram (note the index starts from 1 but gray level starts from 0);
for i=1:row
for j=1:col
% Your code here!  
end
end

% Step 2: compute PDF;
PDF= % Your code here!

% Step 3: compute CDF (Hint: use 'cumsum' function, type 'help cumsum' to see help)
CDF= % Your code here!

% Step 4: compute transformation T (T=CDF*(L-1) and L=256);
T= % Your code here!

% Step 5: generate output image using transformation T;
for i=1:row
for j=1:col
OutIm(i,j)= % Your coder here!
end
end

>>clear all >>close all >> I=imread ('tire . tif' ); >> J=histeg (1); >> Out 1m=HistogramEg(1); >>figure (1) >>subplot (1,2,1) >>subplot (1,2,2)

Explanation / Answer


GIm=imread('tire.tif');
numofpixels=size(GIm,1)*size(GIm,2);
figure,imshow(GIm);
title('Original Image');
HIm=uint8(zeros(size(GIm,1),size(GIm,2)));
freq=zeros(256,1);
probf=zeros(256,1);
probc=zeros(256,1);
cum=zeros(256,1);
output=zeros(256,1);
%freq counts the occurrence of each pixel value.
%The probability of each occurrence is calculated by probf.
for i=1:size(GIm,1)
    for j=1:size(GIm,2)
        value=GIm(i,j);
        freq(value+1)=freq(value+1)+1;
        probf(value+1)=freq(value+1)/numofpixels;
    end
end
sum=0;
no_bins=255;
%The cumulative distribution probability is calculated.
for i=1:size(probf)
   sum=sum+freq(i);
   cum(i)=sum;
   probc(i)=cum(i)/numofpixels;
   output(i)=round(probc(i)*no_bins);
end
for i=1:size(GIm,1)
    for j=1:size(GIm,2)
    HIm(i,j)=output(GIm(i,j)+1);
    end
end
figure,imshow(HIm);
title('Histogram equalization');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote