MATLAB: Setting the position of an image in a figure

Image Processing Toolbox

I have three images in the figure as shown below.
1. I want to display these three images at the center of the figure. How can I do it?
2. I want that automatically the value of mean for each figure is picked from the variable and displayed under each image. How can I do it?
Please explain. Thank you.

Best Answer

Use subplot(), mean2(), and xlabel():
fontSize = 20;
% Make 3 images.
grayImage1 = imread('cameraman.tif');
grayImage2 = imread('moon.tif');
grayImage3 = imread('pout.tif');
% Display image 1 and mean of that image.
subplot(1, 3, 1);
imshow(grayImage1, []);
title('cameraman.tif', 'FontSize', fontSize, 'Interpreter', 'None');
mean1 = mean2(grayImage1);
caption = sprintf('Mean = %.2f', mean1);
xlabel(caption, 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Display image 2 and mean of that image.
subplot(1, 3, 2);
imshow(grayImage2, []);
title('moon.tif', 'FontSize', fontSize, 'Interpreter', 'None');
theMean = mean2(grayImage2);
caption = sprintf('Mean = %.2f', theMean);
xlabel(caption, 'FontSize', fontSize);
% Display image 3 and mean of that image.
subplot(1, 3, 3);
imshow(grayImage3, []);
title('pout.tif', 'FontSize', fontSize, 'Interpreter', 'None');
mean3 = mean2(grayImage3);
caption = sprintf('Mean = %.2f', mean3);
xlabel(caption, 'FontSize', fontSize);
Related Question