histogram of image
1 次查看(过去 30 天)
显示 更早的评论
Hi..
what is bimodel histogram and how apply it to the image. For what it is used
0 个评论
回答(2 个)
Image Analyst
2012-5-13
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.
Image Analyst
2012-5-15
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning for Image Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!