how to display images in separate figures?
Show older comments
I have already implemented my images I need to work with in matlab with imread
Now I want to open each image in one figure. I want to know how I can it open them without wirting severel times the same thing.
I tried it like this but it doesn't work:
for k = 1:8
name = ['im', num2str(k)];
figure; imshow(name)
end
Answers (2)
Image Analyst
on 30 May 2020
What is the extension? Let's say it's png, and you have im1.png, im2.png, etc. So see the FAQ: https://matlab.fandom.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
You need to do something like this:
% Read im1.png through im8.png. Files are in the current directory.
% Change the call to fullfile() if you need to prepend some other folder than the current folder.
for k = 1 : 8
% Create an image filename, and read it in to a variable called thisImage.
baseFileName = sprintf('im%d.png', k);
fullFileName = fullfile(pwd, baseFileName);
if isfile(fullFileName)
thisImage = imread(fullFileName);
else
fprintf('File %s does not exist.\n', fullFileName);
end
% Display the image.
figure % Bring up a new figure;
imshow(thisImage, []);
axis('on', 'image');
caption = sprintf('"%s"', baseFileName);
title(caption, 'FontSize', 15);
end
madhan ravi
on 30 May 2020
for k = 1:8
figure(k)
I = imread(sprintf('im%d',k)); % you forgot to read the image
imshow(I)
end
9 Comments
Mirsamir Salahov
on 30 May 2020
madhan ravi
on 30 May 2020
I can't help unless you reveal what 'file path' is.
Mirsamir Salahov
on 30 May 2020
madhan ravi
on 30 May 2020
Edited: madhan ravi
on 30 May 2020
You need to be more precise, if you want a more precise answer.
Mirsamir Salahov
on 30 May 2020
madhan ravi
on 30 May 2020
Edited: madhan ravi
on 30 May 2020
How are your images named? If it’s named image1-image8 then
I = imread(sprintf('C:\image%d.jpg',k));
Mirsamir Salahov
on 30 May 2020
Edited: Mirsamir Salahov
on 30 May 2020
madhan ravi
on 30 May 2020
Man you are complicating a simple problem.
Mirsamir Salahov
on 30 May 2020
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!