Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to change the range of histogram?

Subject: How to change the range of histogram?

From: Mohd Farhan

Date: 30 Dec, 2011 06:35:09

Message: 1 of 6

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.

Subject: How to change the range of histogram?

From: Nasser M. Abbasi

Date: 30 Dec, 2011 07:26:45

Message: 2 of 6

On 12/30/2011 12:35 AM, Mohd Farhan wrote:
> 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.


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

Subject: How to change the range of histogram?

From: Learner

Date: 30 Dec, 2011 09:51:08

Message: 3 of 6

"Nasser M. Abbasi" <nma@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.

Subject: How to change the range of histogram?

From: Godzilla

Date: 31 Dec, 2011 15:49:08

Message: 4 of 6

"Learner" wrote in message <jdk1ic$n9b$1@newscl01ah.mathworks.com>...
> "Nasser M. Abbasi" <nma@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.

It seems that you just want to change the tick marks on the histogram plot.

Subject: How to change the range of histogram?

From: ImageAnalyst

Date: 31 Dec, 2011 21:13:59

Message: 5 of 6

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]);

Subject: How to change the range of histogram?

From: Learner

Date: 2 Jan, 2012 12:56:07

Message: 6 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0d99c30c-1f41-4dd0-8ff1-903e660d46c0@g41g2000yqa.googlegroups.com>...
> 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]);

thnks.. it works..

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us