Could you tell me how to compare the levels of gray between several photographs and show (increase)it on the graph ? By histogram ?
MATLAB: Compare the levels of gray
graphhistogramimageImage Processing Toolbox
Related Solutions
Let's say you had a masked image where a huge number of pixels were black and this produced a big spike in the histogram at zero. You can suppress this by setting that bin to zero.
[pixelCount, grayLevels] = imhist(grayImage, 256);% Suppress zero bin:
pixelCount(1) = 0;% Now plot:
bar(grayLevels, pixelCount);
I see no reason why imquantize() won't work. Please show your code that demonstrates why imquantize() fails.
Alternatively you can use mat2gray followed by multiplication, as this demo shows:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;format compact;fontSize = 15;% 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');baseFileName = baseFileName;% 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; endendgrayImage = 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);grid on;title('Histogram of original image', 'FontSize', fontSize);xlim([0 grayLevels(end)]); % Scale x axis manually.
% Quantize
numberOfGrayLevels = 4;quantizedImage = uint8(mat2gray(grayImage) * (numberOfGrayLevels-1));% Display the original gray scale image.subplot(2, 2, 3);imshow(quantizedImage, []);caption = sprintf('Image quantized into %d gray levels', numberOfGrayLevels);title(caption, '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(quantizedImage);subplot(2, 2, 4); bar(pixelCount);grid on;caption = sprintf('Histogram of image quantized into %d gray levels', numberOfGrayLevels);title(caption, 'FontSize', fontSize);lastGL = find(pixelCount>0, 1, 'last');xlim([0 lastGL+1]); % Scale x axis manually.
Best Answer