Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to change the range of histogram?

228 views
Skip to first unread message

Mohd Farhan

unread,
Dec 30, 2011, 1:35:09 AM12/30/11
to
hello,

actually i want to change the range of gray scale image histogram...
i.e. let suppose i divide gray scale histogram in 4 parts: from 0-75, 76-150, 151-200, 201-255.
Now i want to allot new range for all the four new sub-histograms i.e. let suppose..
for 0-75 --> i want to scale it in new range from 0-100.
for 76-150 --> i want to scale it in new range from 50-150.
for 151-200 --> i want to scale it in new range from 100-200.
for 210-255 --> i want to scale it in new range from 50-240.
AND AFTER THAT I WANT TO SEE INDIVIDUAL imhist OF ALL THE FOUR NEW SCALED SUB-HISTOGRAMS.

^^ HOW CAN I DO THIS?

PLEASE HELP ME OUT.

Nasser M. Abbasi

unread,
Dec 30, 2011, 2:26:45 AM12/30/11
to
Is this what called histogram equalization? if so, help histeq,
and see code at Matlab central for this.

if not, may be someone else can help.

--Nasser

Learner

unread,
Dec 30, 2011, 4:51:08 AM12/30/11
to
"Nasser M. Abbasi" <n...@12000.org> wrote in message
> Is this what called histogram equalization? if so, help histeq,
> and see code at Matlab central for this.
>
> if not, may be someone else can help.
>
> --Nasser

it is not histogram equalization.. it is different thing.

Godzilla

unread,
Dec 31, 2011, 10:49:08 AM12/31/11
to
"Learner" wrote in message <jdk1ic$n9b$1...@newscl01ah.mathworks.com>...
It seems that you just want to change the tick marks on the histogram plot.

ImageAnalyst

unread,
Dec 31, 2011, 4:13:59 PM12/31/11
to
Mohd:
You want linspace to create the new range, and intlut to remap the
gray levels. This is NOT histogram equalization. See this demo:

% by ImageAnalyst
% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% 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.', 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(3, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(3, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.

% for 0-75 --> i want to scale it in new range from 0-100.
% for 76-150 --> i want to scale it in new range from 50-150.
% for 151-200 --> i want to scale it in new range from 100-200.
% for 210-255 --> i want to scale it in new range from 50-240.
% Create the new mapping using linspace.
lut(1:76) = uint8(linspace(0, 100, 76));
lut(77:151) = uint8(linspace(50,150, 75));
lut(152:201) = uint8(linspace(100, 200, 50));
lut(202:256) = uint8(linspace(50, 240, 55));

% Create the output image using the function intlut().
outputImage = intlut(grayImage, lut);
% Display the output gray scale image.
subplot(3, 2, 3);
imshow(outputImage, []);
title('Output Image', 'FontSize', fontSize);

% Let's compute and display the histogram.
[pixelCount2 grayLevels2] = imhist(outputImage);
subplot(3, 2, 4);
bar(pixelCount);
title('Histogram of output image', 'FontSize', fontSize);
xlim([0 grayLevels2(end)]); % Scale x axis manually.

% Plot each range independently.
% WARNING: Several ranges overlapped and were combined in to the same
range.
% Plot the range 0-100
subplot(3, 4, 9);
bar(0:100, pixelCount2(1:101));
xlim([0 255]);
% Plot the range 50-150
subplot(3, 4, 10);
bar(50:150, pixelCount2(51:151));
xlim([0 255]);
% Plot the range 100-200
subplot(3, 4, 11);
bar(100:200, pixelCount2(101:201));
xlim([0 255]);
% Plot the range 50-240
subplot(3, 4, 12);
bar(50:240, pixelCount2(51:241));
xlim([0 255]);

Learner

unread,
Jan 2, 2012, 7:56:07 AM1/2/12
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <0d99c30c-1f41-4dd0...@g41g2000yqa.googlegroups.com>...
thnks.. it works..
0 new messages