How can i do BI-HISTOGRAM EQUALIZATION in MATLAB

The folling program i tried but it didn't work properly.
I=imread('tire.tif');
%performing bi-histogram equalization
L=256;
[m,n]=size(I);
len=m*n;
x=reshape(I,len,1);
xm=round(mean(x));
xl=x([x<=xm]);
xu=x([x>xm]);
%%%%%%%%%%%%%%%%%%%%%%%%%%
xlpdf=hist(xl,[0:xm]);
xlnpdf=xlpdf/length(xl);
xupdf=hist(xu,[xm+1:255]);
xunpdf=xupdf/length(xu);
%%%%%%%%%%%%%%%%%%%%%%%%%
skl=xm*xlnpdf*triu(ones(55));
sku=(xm+1)+((L-1-(xm+1))*xunpdf*triu(ones(201)));
sk=[skl,sku];
y0=zeros(m,n);
for k=0:L-1
list=find(I==k); %find locates the non-zero values
y0(list)=sk(k+1);
end
y0=uint8(y0);
imwrite(y0,'biHE.tif','TIFF');
j=imread('biHE.tif');

 Akzeptierte Antwort

Image Analyst
Image Analyst am 5 Mai 2013

0 Stimmen

Use intlut() instead of that for loop. You create a look up table of output values for each input value.

8 Kommentare

Sir, i didn't get your answer, could you please help me in detail...
Have i correctly written the algorithm?
Using this program the value of PSNR is less than that of Globally
equalized image, but actually the PSNR of Bi-histogram is to be greater
than histogram equalization!!!
Well I'm not a big fan of histogram equalization. And I really don't see why separately doing histogram equalization on the low and high gray levels would be any good, but I did what you want, or at least what your algorithm tries to do. Here is the code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% 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');
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
else
baseFileName = 'pout.tif';
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- 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 in the search path folders.', 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);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Calculate mean gray level.
meanGL = mean2(grayImage)
% Let's compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
grid on;
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Put line at mean
yl = ylim;
line([meanGL, meanGL], [yl(1), yl(2)], 'LineWidth', 2, 'Color', 'r');
binaryImageLow = grayImage < meanGL;
binaryImageHigh = grayImage >= meanGL;
% Display the image.
subplot(2, 2, 3);
imshow(binaryImageLow, []);
title('Binary Image Below Mean', 'FontSize', fontSize);
% Display the image.
subplot(2, 2, 4);
imshow(binaryImageHigh, []);
title('Binary Image Above Mean', 'FontSize', fontSize);
% Get maps for each
[~, lowMap] = histeq(grayImage(binaryImageLow));
[~, highMap] = histeq(grayImage(binaryImageHigh));
% Combine them.
intMeanGL = int32(meanGL);
lookupTable = uint8(256*[lowMap(1:intMeanGL), highMap(intMeanGL+1:end)]);
%========================================================
% Use lookup table to map image.
% KEY PART RIGHT HERE!!!
dualHistEqImage = intlut(grayImage, lookupTable);
%========================================================
% Display the image.
figure;
imshow(dualHistEqImage, []);
title('Output Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
Wow sir, what i was trying to do for many days and you did it within few
minutes!! Amazing sir and thank you very much.
Sir just explain me these codes
% Get maps for each
[~, lowMap] = histeq(grayImage(binaryImageLow)); what does ~ stand for?
[~, highMap] = histeq(grayImage(binaryImageHigh));
% Combine them.
intMeanGL = int32(meanGL);
lookupTable = uint8(256*[lowMap(1:intMeanGL), highMap(intMeanGL+1:end)]);
~ means to ignore that returned argument. I didn't need that image since it would histogram equalize the whole image and I just wanted it on half the image, which I would do later with intlut().
By the way, histogram equalized images usually look pretty bad and unnatural. I never use them.
i'm new in this genre sir, i'm just trying to implement the proposed method of
YEONG-TAEG KIM titled "Contrast Enhancement Using Brightness Preserving Bi-Histogram Equalization"
According to the paper Bi histogram equalization gives out image with better contrast than that of usual global histogram equalization.
But i wonder this program is giving me the output image with with less contrast than global HE based on the measure PSNR( http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio )
If that's using a global histogram equalization but just using each part fo the histogram independently, then I don't see how it would be any good. But I didn't read the paper so perhaps you didn't describe it correctly. Usually if global histogram equalization is no good, which it often isn't, people will use CLAHE, which is a contrast limited locally adaptive histogram equalization. This can be good for some types of images (e.g. images of pages that you want to do OCR on with huge gradients/shading). This is done by the MATLAB function adapthisteq() in the Image Processing Toolbox.
can i use this program for contrast enhancement and brightness preserving using bi histogram equalisation
Who are you asking? All I know is the opinions and guesses I gave in my last comment. I don't have any code for bi-histogram equalization.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by