Clear Filters
Clear Filters

histogram of image

1 view (last 30 days)
Tricky
Tricky on 13 May 2012
Hi..
what is bimodel histogram and how apply it to the image. For what it is used

Answers (2)

Image Analyst
Image Analyst on 13 May 2012
It is a probability distribution function of the intensity values in the image. If it's bimodal it means that there are predominantly two types of things in the image: bright things and dark things. You don't apply it to the image. You might look at it to decide where to threshold the image into foreground and background.
  1 Comment
Tricky
Tricky on 15 May 2012
Thnaks IA and can I get a Demo this ?

Sign in to comment.


Image Analyst
Image Analyst on 15 May 2012
Here's your demo:
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';
% 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);
% 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')
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;
% Specify a threshold
thresholdValue = 50;
% Put a vertical line on the histogram at the threshold.
yl = ylim();
line([thresholdValue thresholdValue], yl, 'Color', 'r', 'LineWidth', 2);
% Threshold the image.
binaryImage = grayImage < thresholdValue;
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Get a masked image.
maskedImage = zeros(rows, columns);
maskedImage(binaryImage) = grayImage(binaryImage);
% Display the binary image.
subplot(2, 2, 4);
imshow(maskedImage, []);
title('Masked Image', 'FontSize', fontSize);

Products

Community Treasure Hunt

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

Start Hunting!