I need Help in Digital Image Processing - Specifically Histogram Equlaization

2 views (last 30 days)
I am working Currently on project that require me to do the following
1)obtain the histogram of an image X 2)play on that histogram and obtain a new one lets say Y
My problem is how can i apply this new histogram to the original image
I'm using the function histeq(I,Map) but my Advisor want me to not use.Which mean i need to build my own function
plz any help even if you can mention the algorithms i will be thankful
Regards

Answers (3)

Image Analyst
Image Analyst on 16 Mar 2012
If you want a good, virtually perfect histogram equalization (unlike the crappy book formula ones out there, or the MATLAB one), then check out my version in my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/28972-custom-shaped-histogram
  1 Comment
James
James on 16 Mar 2012
I looked to what you have did and it's really an amazing work but this very complex for me to understand to what you did i want to implement a simple function just like you did and also you would help me if you can give me the algorithms that you have used
Am student and this a professional for me :)
Regards

Sign in to comment.


Image Analyst
Image Analyst on 16 Mar 2012
I really shouldn't be doing this (your homework) for you, but perhaps it will be instructive for others. Basically you compute the CDF using cumsum() (the CDF is the transfer function to map input gray levels into output gray levels), and apply the equalization with intlut(). Note how non-flat the histogram is and how bad the image looks - both very typical of global histogram equalization methods, which is why it's rarely used.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(3, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(3, 2, 2);
bar(pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Compute the CDF
cdf = uint8(256 * cumsum(pixelCount) / sum(pixelCount));
subplot(3, 2, 3);
plot(cdf);
grid on;
title('Equalization Transfer Function', 'FontSize', fontSize);
% Equalize the image.
heImage = intlut(grayImage, cdf);
% Display the original gray scale image.
subplot(3, 2, 5);
imshow(heImage, []);
title('Equalized Image', 'FontSize', fontSize);
% Let's compute and display the histogram.
[pixelCountHE grayLevelsHE] = imhist(heImage);
subplot(3, 2, 6);
bar(pixelCountHE);
grid on;
title('Histogram of Equalized Image', 'FontSize', fontSize);
xlim([0 grayLevelsHE(end)]); % Scale x axis manually.
  6 Comments
Shatha Jadallah
Shatha Jadallah on 16 Nov 2020
Great explanation!
Is there a way where i can reverse the equalized histogram back to its original?
Image Analyst
Image Analyst on 17 Nov 2020
Possibly. It depends on how the equalization was done.
  1. If all it did was rearrange the location of the bins, then yes, but you'd have to keep track of where each gray level got sent (it's new gray level), which is what the cdf vector is.
  2. If it split or combined bins so that the bin heights are now different, then no.
You can probably tell if you just look at the shape of the histogram. Do the bars just looked moved around (left or right) or have their heights changed?

Sign in to comment.


DHIVYA BHARKAVI
DHIVYA BHARKAVI on 11 Nov 2017
Error in fullFileName

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!