ImageAnalyst
unread,Dec 31, 2011, 4:13:59 PM12/31/11You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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]);