I need Help in Digital Image Processing - Specifically Histogram Equlaization
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(3 个)
Image Analyst
2012-3-16
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
Image Analyst
2012-3-16
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 个评论
Shatha Jadallah
2020-11-16
Great explanation!
Is there a way where i can reverse the equalized histogram back to its original?
Image Analyst
2020-11-17
Possibly. It depends on how the equalization was done.
- 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.
- 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?
DHIVYA BHARKAVI
2017-11-11
Error in fullFileName
1 个评论
Image Analyst
2017-11-11
Then you never assigned any string to it. See this link and repost your issue in a new Question (not here).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!