How to limit the dimension of a 3D matrix?
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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
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?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!