Clear Filters
Clear Filters

Setting the position of an image in a figure

33 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 28 Jan 2016
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);
  3 Comments
Image Analyst
Image Analyst on 28 Jan 2016
Right, because subimage() puts stitched images in one axes. To put labels on that, you'd have to use the text() function to put a test string into the overlay of the image.

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!