clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 22;
folder = pwd;
baseFileName = 'cameraman.tif';
grayImage = imread(baseFileName);
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
grayImage = rgb2gray(grayImage);
end
subplot(2, 2, 1);
cmap = jet(256);
imshow(grayImage, 'Colormap', cmap);
axis('on', 'image');
title('Original Color Map', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
colorbar;
hFig = gcf;
hFig.WindowState = 'maximized';
drawnow;
set(gca,'ColorScale','log')
subplot(2, 2, 2);
imhist(grayImage);
grid on;
title('Histogram', 'FontSize', fontSize, 'Interpreter', 'None');
minGL = 150;
maxGL = 190;
xline(minGL, 'Color', 'r', 'LineWidth', 2);
xline(maxGL, 'Color', 'r', 'LineWidth', 2);
mask = grayImage >= minGL & grayImage <= maxGL;
subplot(2, 2, 3);
imshow(mask);
axis('on', 'image');
title('Mask', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
colorbar;
drawnow;
maskedImage = grayImage;
maskedImage(~mask) = 0;
subplot(2, 2, 4);
imshow(maskedImage, 'Colormap', cmap);
axis('on', 'image');
caption = sprintf('Masked Image with color map applied between %d and %d', minGL, maxGL);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
colorbar;
caxis([minGL, maxGL]);
drawnow;
Best Answer