i hav 384 images.using a for loop i read an img& apply transform on it & store the result in variable named res1 & next i read 2nd img & apply transform on it & store result in variable res2 &so on for rest images.how do i implement this in for loop

1 view (last 30 days)
for i=1:384 %read 1st img. apply transform on it and store result in variable named result1. %during next iteration,read 2nd img,apply transform on it and store result in variable named result2. %similarly for rest images store result in variables names result3,result4,... and so on. % how do i implement this end

Answers (2)

Image Analyst
Image Analyst on 6 Dec 2013

Alex Taylor
Alex Taylor on 6 Dec 2013
Edited: Alex Taylor on 6 Dec 2013
This concept of storing each result in a separate named variable is not very "MATLAB-like". It would be more in model to represent this operation as an MxNx384 matrix as input, with an PxQx384 matrix as output.
If by "transform" you mean a geometric transformation, then the good news is you don't need to write a loop to do this, provided you can have all 384 images represented in memory as an MxNx384 matrix.
Take the following example:
I = imread('peppers.png');
tform = affine2d([1 0 0; .5 1 0; 0 0 1]);
J = imwarp(I,tform);
figure, imshow(I), figure, imshow(J)
The Image I is an MxNx3 RGB image. The reason that J is an RGB sheared version of I is that when a 2-D geometric transformation is applied to an N-D matrix, imwarp applies the 2-D transformation to I one plane at a time.
This plane at a time behavior is featured in several other Image Processing Toolbox functions including imfilter, imerode, imdilate, etc. You should not need to write a loop to accomplish this task.


Find more on Loops and Conditional Statements 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!

Translated by