str2num for looping through images

2 views (last 30 days)
Anand
Anand on 22 Aug 2014
Commented: Image Analyst on 22 Aug 2014
Hi Everyone! I'm trying to have a for loop that will cycle through multiple images. Take my trainer pic for example. There are 3 pictures. Instead of reading the file 3 times, can someone help?
Keep in mind the following
  • trainer1.png,trainer2.png, and trainer3.png are 3 different pictures
  • trainerPic is the axes in which it will be displayed
Here's what I have:
[handles.v1,handles.b,handles.a1] = imread('trainer1.png');
[handles.v2,handles.b,handles.a2] = imread('trainer2.png');
[handles.v3,handles.b,handles.a3] = imread('trainer3.png');
i=true
while(i==true)
% trainer sequence
axes(handles.trainerPic)
handles.V = imshow(handles.v1)
set(handles.V,'AlphaData',handles.a1)
pause(0.3)
handles.V = imshow(handles.v2)
set(handles.V,'AlphaData',handles.a2)
pause(0.3)
handles.V = imshow(handles.v3)
set(handles.V,'AlphaData',handles.a3)
end

Answers (1)

Image Analyst
Image Analyst on 22 Aug 2014
What is handles.a1, a2, and a3? Where did you see that imread() returns 3 outputs? What do you think the third output is supposed to be? I've never used more than 2 outputs and don't see anything in the help about 3 outputs.
  2 Comments
Anand
Anand on 22 Aug 2014
Sorry for the missing details. The while loop works and the 3 images are displayed. I'm just not sure how to use str2num for the trainer 1 .png to trainer 2 .png to trainer*3*.png and forward
Don't worry about the other details. They work :)
Image Analyst
Image Analyst on 22 Aug 2014
I'm really not sure what you want to do and why you have a loop. Do you want to show images #2 and 3 in the overlay (alpha channel) above image #1? Or maybe you want to process a sequence of images, like the FAQ shows you http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F Let us know if we can help further (after you explain better).

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks 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!