How to limit the dimension of a 3D matrix?

1 view (last 30 days)
Hi all,
I'm new to Matlab and currently working on a project which takes in frames of a tif video file(nxmx3010) and builds some 3D images for each 14 frames. . But now, the problem I'm facing is: When I take the first 14 frames of the file, the output 3D image(nxmx14) is good enough for me to do some manipulations, but then, the 3D image of the next 14 frames are having the starting frame:15 and ending frame:28, but, in the 3D image, the dimensions are being represented as nxmx28. The problem with this is, the new 3D matrix is having zero pixels in the 1-14 frames and the rest frames in the matrix are good.
My question is, how to not include the 1-14 empty frames while building 15-28 frame 3D matrix?

Answers (1)

Walter Roberson
Walter Roberson on 28 Jun 2016
Example:
dinfo = dir('*.jpg');
numfiles = length(dinfo);
for groupbase = 0 : 14 : (numfiles + 1)
imgset = [];
for imgoffset = 1 : 14
imgnum = groupbase + imgoffset;
this_image = imread( dinfo(imgnum).name );
imgset(:, :, imgoffset) = this_image;
end
... now work with imgset
end
Alternately:
dinfo = dir('*.jpg');
numfiles = length(dinfo);
for imgnum = 1 : numfiles
this_image = imread( dinfo(imgnum).name );
imgoffset = 1 + mod(imgnum - 1, 14);
imgset(:, :, imgoffset) = this_image;
if imgoffset == 14
... now work with imgset
end
end
  2 Comments
Varshini Guddanti
Varshini Guddanti on 28 Jun 2016
Thanks for your reply! The code tend to output only one 3D matrix(1-14 frames).But I need 215 matrices( which is 3010 /14). I tried:
InfoImage=imfinfo(FileTif);
nFrames=length(InfoImage);
for i = 1:nFrames
if(mod(i,14) == 0)
for m=FirstSlice:LastSlice
MatrixName(:,:,m) = imread(FileTif,'Index',m);
end
end
end
With this code, I'm able to get 215 images but if we see the matrices except the first one, I'm getting zero pixels from 1 until the start of the new matrix.
Can you please fix this?
Walter Roberson
Walter Roberson on 28 Jun 2016
Your code does not define FirstSlice or LastSlice.
I am not clear as to whether you have multiple files?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!