From: Vikas Bajpai on
Sir
I have an error image so the matrix of image contains some negative
values as well now I want to draw a histogram, but by using imhist I
am able to show the positive values only, so what to do so that the
histogram also contains the negative values as well.
From: Dave Robinson on
Vikas Bajpai <vikas.bajpai87(a)gmail.com> wrote in message <11dc73d7-44e4-4fbb-b024-798009155bb8(a)u3g2000prl.googlegroups.com>...
> Sir
> I have an error image so the matrix of image contains some negative
> values as well now I want to draw a histogram, but by using imhist I
> am able to show the positive values only, so what to do so that the
> histogram also contains the negative values as well.

As you have discovered imhist has been optimized for use with greyscale images, which in the standard uint8 format only recognizes pixel intensities of 0 --> 255. You can't use imhist as it stands for your application. You can try simple stunts like giving your data a 'fat' zero by rescaling your image so that the numerical pixel value 0 corresponds to say an intensity of -255 or whatever is appropriate. An alternative would be not to use imhist, but one of its brethren

help hist

Regards

Dave Robinson
From: Vikas Bajpai on
On May 12, 2:58 pm, "Dave Robinson" <dave.robin...(a)somewhere.biz>
wrote:
> Vikas Bajpai <vikas.bajpa...(a)gmail.com> wrote in message <11dc73d7-44e4-4fbb-b024-798009155...(a)u3g2000prl.googlegroups.com>...
> > Sir
> > I have an error image so the matrix of image contains some negative
> > values as well now I want to draw a histogram, but by using imhist I
> > am able to show the positive values only, so what to do so that the
> > histogram also contains the negative values as well.
>
> As you have discovered imhist has been optimized for use with greyscale images, which in the standard uint8 format only recognizes pixel intensities of 0 --> 255. You can't use imhist as it stands for your application. You can try simple stunts like giving your data a 'fat' zero by rescaling your image so that the numerical pixel value 0 corresponds to say an intensity of -255 or whatever is appropriate. An alternative would be not to use imhist, but one of its brethren
>
> help hist
>
> Regards
>
> Dave Robinson

ok sir
but how to implement that, please help me with the code
From: Airballman on
I think a simple solution would be gained using those three lines :


M = M - min(M(:));
M = M/max(M(:));
M=255*M;

In thsi way, your matrix will be normalized to 8-bit greyscale format.
You can then use imhist.

However, I can't be sure without any example of matrix you may have.

Just have and try and come back is there is stil problems
From: ImageAnalyst on
On May 12, 2:23 am, Vikas Bajpai <vikas.bajpa...(a)gmail.com> wrote:
> Sir
> I have an error image so the matrix of image contains some negative
> values as well now I want to draw a histogram, but by using imhist I
> am able to show the positive values only, so what to do so that the
> histogram also contains the negative values as well.

--------------------------------------------------------------------------------------
Vikas:
It certainly is possible to take the histogram of a floating point
image with imhist. The key is that you have to scale it to 0-1
first. Then you have to do a few little tricks if you want the axis
to be the original levels and not the 0-1 levels. Study this demo and
it will show you how to do it:
IMPORTANT: BE SURE TO JOIN ANY LINES BROKEN INTO TWO BY THE
NEWSREADER.
-ImageAnalyst

% function double_image_histogram()

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Read in standard MATLAB gray scale demo image.
grayImage = imread('cameraman.tif');
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% Let's get its histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 3);
bar(pixelCount);
xlim([0 grayLevels(end)]); % Scale x axis manually.
title('Original Grayscale Histogram', 'FontSize', fontSize);

% Now let's synthesize an image that is a floating point
% image and has values from -12345 to +54321.
originalMinValue = double(min(min(grayImage)))
originalMaxValue = double(max(max(grayImage)))
originalRange = originalMaxValue - originalMinValue;

% Get a double image in the range -127 to +128
desiredMin = -45678;
desiredMax = 54321;
desiredRange = desiredMax - desiredMin;
dblImageS = desiredRange * (double(grayImage) - originalMinValue) /
originalRange + desiredMin;

% So now we have a double image that is our "starting image."
% However can't use imhist on this. We need to scale to 0-1.
minValueS = min(min(dblImageS))
maxValueS = max(max(dblImageS))
rangeS = maxValueS - minValueS;
dblImage = (dblImageS - minValueS) / rangeS;
% Check to verify that range is now 0-1.
minValueNorm = min(min(dblImage))
maxValueNorm = max(max(dblImage))
subplot(2, 2, 2);
imshow(dblImage, []);
title('Double Image', 'FontSize', fontSize);

% Let's get its histogram into 256 bins.
[pixelCountD grayLevelsD] = imhist(dblImage, 256);
% But now grayLevelsD goes from 0 to 1.
% We want it to go from the original range, so we need to scale.
originalDoubleGrayLevels = rangeS * grayLevelsD + minValueS;

subplot(2, 2, 4);
plot(originalDoubleGrayLevels, pixelCountD);
title('Histogram of double image', 'FontSize', fontSize);
% Scale x axis manually.
xlim([originalDoubleGrayLevels(1) originalDoubleGrayLevels(end)]);