function imageArray = DisplayImage(handles, fullImageFileName)
imageArray = [];
try
[imageArray, colorMap] = imread(fullImageFileName);
catch ME
errorMessage = sprintf('Error in program %s, function %s(), at line %d.\n\nError Message:\n%s', ...
mfilename, ME.stack(1).name, ME.stack(1).line, ME.message);
uiwait(warndlg(errorMessage));
return;
end
try
hold off;
imshow(imageArray, 'InitialMagnification', 'fit', 'parent', handles.axesImage);
[folder, basefilename, extension] = fileparts(fullImageFileName);
extension = lower(extension);
caption = [basefilename, extension];
title(handles.axesImage, caption, 'Interpreter', 'none', 'FontSize', 14);
[rows, columns, numberOfColorChannels] = size(imageArray);
fileInfo = dir(fullImageFileName);
txtInfo = sprintf('%s\n\n%d lines (rows) vertically\n%d columns across\n%d color channels\n', ...
[basefilename extension], rows, columns, numberOfColorChannels);
if numberOfColorChannels == 3
colorbar 'off';
txtInfo = sprintf('%s\nThis is a true color, RGB image.', txtInfo);
elseif numberOfColorChannels == 1 && isempty(colorMap)
colorbar 'off';
txtInfo = sprintf('%s\nThis is a gray scale image, with no stored color map.', txtInfo);
elseif numberOfColorChannels == 1 && ~isempty(colorMap)
txtInfo = sprintf('%s\nThis is an indexed image. It has one "value" channel with a stored color map that is used to pseudocolor it.', txtInfo);
colormap(colorMap);
whos colorMap;
colorbar('peer', handles.axesImage);
end
catch ME
errorMessage = sprintf('Error in program %s, function %s(), at line %d.\n\nError Message:\n%s', ...
mfilename, ME.stack(1).name, ME.stack(1).line, ME.message);
uiwait(warngld(errorMessage));
end
uiwait(helpdlg(txtInfo));
return;
Best Answer