user1745078
user1745078

Reputation: 19

Create a circular buffer for image acquisition

I'm new in programming with matlab and trying to do the following:

I continously capture an image (size 1024x1024) with a camera to have a live image using the getdata function. To do a measurement I would like to store only 100 images using a circular buffer- more precisely I'm thinking of storing 100 images and erasing the oldest images if new data is acquired and do a measurement on the last 100 images.

Hope my concern is understandable...

Thanks for an answer!

Upvotes: 1

Views: 1623

Answers (3)

lucasg
lucasg

Reputation: 11002

This question has been answered here by a worker from MathWorks : Create a buffer matrix for continuous measurements. ( He also made a video of it : http://blogs.mathworks.com/videos/2009/05/08/implementing-a-simple-circular-buffer/

The code :

buffSize = 10;
circBuff = nan(1,buffSize);
for newest = 1:1000;
   circBuff = [newest circBuff(1:end-1)]
end

Check the update made by gnovice which applies the circular buffer to image processing.

Upvotes: 1

base_128
base_128

Reputation: 11

May you can create an array of 100 1024x1024-matrices. and refer the following link to maintain the read and write position. logic of circular buffer

Upvotes: 0

Bitwise
Bitwise

Reputation: 7807

What you call a "circular buffer" is known as a queue or FIFO (First In, First Out). Usually this would be stored in a linked list data structure, where every object (matrix, in your case) points to the next object. In Matlab however, there is not built-in linked list structure, but Matlab arrays (vectors/matrices) are pretty flexible and efficient when it comes to manipulating them.

So you can simply store each image as a matrix inside an array of length 100, giving you a 3 dimensional matrix of dimensions 100x1024x1024. Then, when you get new data you simply remove the last matrix from the array and insert a new matrix at the beginning of the array. Hopefully this will be fast enough for you.

Good luck!

Upvotes: 0

Related Questions