Clear Filters
Clear Filters

Reading a sequence of image frames (bmp) and storing it as a 4-D array

5 views (last 30 days)
I need to read a sequence of image frames (bmp) and store it as a 4-D array (mXnX3Xp) where p=no. of frames. When I try to do this using an array named 'image', I don't get an error but get an 1-D array instead. Checking size(image) returns pX1.
My code for reading a single frame is:
A=imread('cropped_sequence0000.bmp'); %All images are named as cropped_sequence0000 to 0999
B=A(:,:,3); %Extract blue channel only
C=size(B);
d=C(:,2); %Find width of each frame
h=C(:,1); %Find height of each frame
if mod(d,2)==0 %Take half-width for analysis
f=d/2;
else
f=(d+1)/2;
end
if mod(h,2)==0 %Take half-height for analysis
i=h/2;
else
i=(h+1)/2;
end
G=B([i:h],f); %Read desired area of interest
P=size(G);
q=P(:,1);
J=[1:q];
[k,l]=min(G(:)); %Find extrema of blue pixels
[m,n]=max(G(:));
plot(J,G)
Now, I read the entire directory as follows:
for i=1:999
image{i}=imread(sprintf('cropped_sequence%.4d.bmp',i));
end
I expected image to be a 4-D array but it turns out to be an 1-D array of size 999. I want to have a 4-D array that reads all the individual frame information by reading each frame in tandem as in the single frame code above. Finally, I need to plot the locations of the extrema of blue pixels versus frame number.

Accepted Answer

Image Analyst
Image Analyst on 4 Jan 2014
What are you doing plotting G - the blue channel image??? To create a 3D image you use cat():
if imageNumber = 0
image4D = G; % First image - nothing to concatenate onto yet.
else
image4D = cat(3, image4D, G); % Concatenate an image onto the 4D array.
end
  4 Comments
Image Analyst
Image Analyst on 7 Jan 2014
Edited: Image Analyst on 7 Jan 2014
I called it G because that's what you called your image in your original code. But you're not using that anyway. You're now calling the image temp_img, and that's fine. It looks like your latest code should construct the 4D image properly once you change image4d into image4D - MATLAB is case sensitive. And change this line:
mat_plot(j)=temp_img;
to
mat_plot = temp_img;
or just get rid of mat_plot altogether and use only temp_img.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!