Question

6. Write Matlab code to open, cameraman.tif and then produce and display an image that is a contrasted adjusted version of the original image, with output values spanning from 0 to 255. (6 points) 255 alpMa a. 0 lo Input values high

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Image Enhance contrast can be done using histogram equalization in matlab
In histogram equalization the work is to trying to maximize the image contrast by applying a gray level transform which tries to flatten the resulting histogram.
It turns out that the gray level transform that we are seeking is simply a scaled version of the original image's cumulative histogram.
That is, the gray level transform T is given by T[i] = (G-1)c(i), where G is the number of gray levels and c(i) is the normalized cumulative histogram of the original image.
The code is below

I=imread('cameraman.tif');
numofpixels=size(I,1)*size(I,2);
figure,imshow(I);
title('Original Image');
Histo_Img=uint8(zeros(size(I,1),size(I,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(I,1)
for j=1:size(I,2)
value=I(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(I,1)
for j=1:size(I,2)
Histo_Img(i,j)=output(I(i,j)+1);
end
end
figure,imshow(Histo_Img);
title('Histogram equalization');

Add a comment
Know the answer?
Add Answer to:
6. Write Matlab code to open, cameraman.tif and then produce and display an image that is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT