how do I show the images name on top of each picture
4 views (last 30 days)
Show older comments
0 Comments
Accepted Answer
Yongjian Feng
on 25 Nov 2021
Edited: Yongjian Feng
on 25 Nov 2021
Add a title to each subplot, after you call subplot:
title('Horse')
2 Comments
Yongjian Feng
on 25 Nov 2021
Yeah, instead of ',', use ';'.
subplot(2,2,3);
title ('Bicycle');
imshow(readimage(imds,tricycle));
More Answers (1)
Image Analyst
on 25 Nov 2021
Another option, other than title(), is to put the filename in text in the overlay
rgbImage = imread(filename);
imshow(rgbImage);
text(10, 10, filename, 'Color', 'r', 'FontSize', 20, 'VerticalAlignment', 'top');
2 Comments
Image Analyst
on 25 Nov 2021
I'm sure you figured it out by now, but it would go something like this:
fontSize = 20;
folder = pwd;
imds = imageDatastore(folder, "FileExtensions",[".jpg",".tif"])
numImages = length(imds.Files)
plotRows = ceil(sqrt(numImages))
for k = 1 : numImages
thisFile = imds.Files{k}
[f, baseFileName, ext] = fileparts(thisFile);
thisImage = imread(thisFile);
subplot(plotRows, plotRows, k);
imshow(thisImage);
title(baseFileName, 'FontSize', fontSize);
text(10, 10, baseFileName, 'Color', 'r', ...
'BackgroundColor', 'y', 'FontSize', fontSize, 'VerticalAlignment', 'top')
end
g = gcf;
g.WindowState = 'maximized'
I show the name both as a title and in the overlay.
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!