how to plot histogram in 12-bit from an 16-bit image?

  • Follow


hi guys,

so in my university project, i need to plot a histogram in 12-bit portrayal (the x-axis is from 0 - 4096 gray values) from an 16-bit image.. with software ImageJ i could do that with no problem at all, i just need to divide the image with 16 (16bit / 16 = 12bit, 65536/16 = 4096) and then i just call the histogram... i wish i could show you how it looks like, but there's no option here to attach something..

in matlab i've written this code:

f = imread('D:\.....\20091007080643421.tif');
imhist(f), ylim([0,21000]); %figure 1
g = imdivide(f,16);
figure, imhist(g), ylim([0,21000]); %figure 2
figure, imhist(g), ylim([0,21000]), xlim([0,4096]); %figure 3 is the same as figure 2, with different scale

but it looks completely different from with what i've done in ImageJ... but i really need to make this in matlab for this project..
can somebody please help me..?

cheers,
Dalle
0
Reply Dalle 6/5/2010 1:26:04 PM

Dalle:
fromt he help: "imhist(I, n) displays a histogram where n specifies
the number of bins used in the histogram. "

Run this demo and you'll understand:

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

% Read in standard MATLAB grayscale demo image.
grayImage = imread('cameraman.tif');
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image');
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

% Let's get its histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image');
xlim([0 grayLevels(end)]); % Scale x axis manually.

% Convert to a 16 bit image
grayImage16 = 256 * uint16(grayImage);

% Let's get its 16 bit histogram.
numberOfBins16 = double(intmax('uint16'));
[pixelCount16 grayLevels16] = imhist(grayImage16, numberOfBins16);
subplot(2, 2, 3);
bar(grayLevels16, pixelCount16);
title('Histogram of 16 bit image');
xlim([0 grayLevels16(end)]); % Scale x axis manually.

% Convert 16 bit image to a 12 bit image.
grayImage12 = uint16(grayImage16 / 16);
numberOfBins12 = round(numberOfBins16 / 16);

% Let's get its 12 bit histogram.
[pixelCount12 grayLevels12] = imhist(grayImage12, numberOfBins12);
subplot(2, 2, 4);
bar(grayLevels12, pixelCount12);
title('Histogram of 12 bit image');
xlim([0 grayLevels12(end)/16]); % Scale x axis manually.



0
Reply ImageAnalyst 6/5/2010 2:50:45 PM


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <b791d49b-0a72-4d0d-a3b8-403da498fbbc@d37g2000yqm.googlegroups.com>...
> Dalle:
> fromt he help: "imhist(I, n) displays a histogram where n specifies
> the number of bins used in the histogram. "
> 
> Run this demo and you'll understand:
> 
> 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
> 
> % Read in standard MATLAB grayscale demo image.
> grayImage = imread('cameraman.tif');
> subplot(2, 2, 1);
> imshow(grayImage, []);
> title('Original Grayscale Image');
> set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
> screen.
> 
> % Let's get its histogram.
> [pixelCount grayLevels] = imhist(grayImage);
> subplot(2, 2, 2);
> bar(pixelCount);
> title('Histogram of original image');
> xlim([0 grayLevels(end)]); % Scale x axis manually.
> 
> % Convert to a 16 bit image
> grayImage16 = 256 * uint16(grayImage);
> 
> % Let's get its 16 bit histogram.
> numberOfBins16 = double(intmax('uint16'));
> [pixelCount16 grayLevels16] = imhist(grayImage16, numberOfBins16);
> subplot(2, 2, 3);
> bar(grayLevels16, pixelCount16);
> title('Histogram of 16 bit image');
> xlim([0 grayLevels16(end)]); % Scale x axis manually.
> 
> % Convert 16 bit image to a 12 bit image.
> grayImage12 = uint16(grayImage16 / 16);
> numberOfBins12 = round(numberOfBins16 / 16);
> 
> % Let's get its 12 bit histogram.
> [pixelCount12 grayLevels12] = imhist(grayImage12, numberOfBins12);
> subplot(2, 2, 4);
> bar(grayLevels12, pixelCount12);
> title('Histogram of 12 bit image');
> xlim([0 grayLevels12(end)/16]); % Scale x axis manually.
> 
> 

my god... you're really a genius aren't you :D 
thx so much ImageAnalyst, that's really make my life easier now, hehehe..
again thx a bunch!
1
Reply Dalle 6/5/2010 3:10:05 PM

2 Replies
501 Views

(page loaded in 0.022 seconds)

Similiar Articles:













7/23/2012 12:57:21 AM


Reply: