From: Dalle Ali on
hi guys,

is it possible to extract data from an image-histogram as two simple x & y-datas? i've tried to use the function get(..., 'Xdata') but it only delivers [1x4096 double]...
what i need is as if the image-histogram like a simple plot, so i can extract every points from the histogram, and maybe later import that to excel or something..

is there any way to do that?
thx before...

cheers,
Dalle
From: Walter Roberson on
Dalle Ali wrote:

> is it possible to extract data from an image-histogram as two simple x &
> y-datas? i've tried to use the function get(..., 'Xdata') but it only
> delivers [1x4096 double]...

histx = get(...,'XData');
histy = get(...,'YData');
From: ImageAnalyst on
Dalle:
I'm not sure what you mean. Do you mean like your "y-data" is the
Pixel Counts (the values in the bins), and your "x-data" is the gray
level? If so, they are returned as the two return values of imhist(),
like in this demo:

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(3, 1, 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);

% First plot as a bar chart.
subplot(3, 1, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.

% Now plot as line plot.
subplot(3, 1, 3);
plot(grayLevels, pixelCount, 'LineWidth', 2);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
From: Dalle Ali on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <915e6447-c55b-4341-a448-631bd73ff2dc(a)k39g2000yqb.googlegroups.com>...
> Dalle:
> I'm not sure what you mean. Do you mean like your "y-data" is the
> Pixel Counts (the values in the bins), and your "x-data" is the gray
> level? If so, they are returned as the two return values of imhist(),
> like in this demo:
>
> 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(3, 1, 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);
>
> % First plot as a bar chart.
> subplot(3, 1, 2);
> bar(pixelCount);
> title('Histogram of original image', 'FontSize', fontSize);
> xlim([0 grayLevels(end)]); % Scale x axis manually.
>
> % Now plot as line plot.
> subplot(3, 1, 3);
> plot(grayLevels, pixelCount, 'LineWidth', 2);
> title('Histogram of original image', 'FontSize', fontSize);
> xlim([0 grayLevels(end)]); % Scale x axis manually.

yes ImageAnalyst, that's exactly what i meant that y-Data is the Pixel Count and x-Data is the Gray Values... your example works great and i'm really thankful for that :)
it's just i got a bit of a jam about it and i kinda need your wisdom once more...

so this is what i've written for my code:

img = imread('.... .tif'); %read an image
[PixelCount GrayValues] = imhist(img);
imhist(img); %so far so good, i've checked in workspace and PixelCount has 256 datas as well as GrayValues

%now i need to plot the histogram in 12-bit view

img12 = uint16(img/16); %convert 16 bit image to 12 bit image
[pixel12 gray12] = imhist(img12, round(double(intmax(('uint16')))/16));
figure, plot(gray12, pixel12), xlim([0,4096]);

so up to that point, the second figure which shows the histogram in 12-bit view looks right, BUT at the workspace pixel12 and gray12 both has 4096 datas, even though the original image has only 256 datas both in pixel counts and the gray values...
so i'm clearly lost at this point... can you explain to me why?

cheers,
Dalle
From: ImageAnalyst on
I think 256 must be the default for uint8 and 4096 for uint16
regardless of how the gray levels are ACTUALLY distributed in there.
So the upper bins could be zero but they'll still be there. This is
convenient because you don't want different sized histograms every
time you take the hist of a grayscale image. Since you didn't scale
your image it still lies in the 0-255 range and the bins from 256-4095
are probably all zero.