How to store values continuously without overwriting the previous one?

5 views (last 30 days)
My project is "optical flow estimation for flame detection in videos" In that while extracting feature values,i can only retain the last intensity value of the frame.. here is my coding
function [Iy, Ix, It] = grad3D(imNew,bFineScale,bInitialize) persistent siz gx gg imPrev; %filters and previous image % initialize persistent variables, these will remain between calls
if nargin>2 && bInitialize %make the filters gx (for x-derivative) and gg (for smoothing) [gx, gg]= makeFilters(); if bFineScale
siz = size(imNew);
imPrev= single(imNew);
else% if ~bFineScale
siz = floor(size(imNew)/2);
%initialize imPrev to half the size
imPrev = imresizeNN(single(imNew),siz);
end
end
%%% resample image to right resolution, depending on the scale we chose: if ~bFineScale imNew = imresizeNN(conv2(single(imNew),gg,'same'),siz); else imNew = single(imNew); end
% more like a steerable filter(conforms better to the optical flow % constraint): Ix = conv2(gg,gx,imNew + imPrev,'same'); %L1 Iy = conv2(gx,gg,imNew + imPrev,'same'); %L2 It = conv2(gg,gg,imNew - imPrev,'same'); %L3
% finally, store away the current image for use on next frame imPrev = imNew; imwrite(imPrev,['final\',num2str(i),'.jpg']); testfeature = mean(imPrev);
save testfeature testfeature
%%%% a local helper function %%%%% function [gx, gg]= makeFilters() x = (-1:1); gg = single(gaussgen(0.67,3)); gx = single(-x.*gg*3);
In the highlighted coding...i can be able to get only the intensity value of last frame extracted...But i need the values for all the extracted frames...So please help me with that...And i need the value to be stored row wise in a matrix file....
  1 Comment
LUI PAUL
LUI PAUL on 1 Apr 2015
i am not specialized on this field but generally my view is.... are u searching for this?
A=[1 2 3];%first value B=[3 4 5];%second value A=[A;B]; B=[4 5 6];%third value A=[A;B]; . . . so on

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 31 Mar 2015
So I didn't try to delve into your code, but generally to prevent subsequent iterations from overwriting prior results, you need to store your results in an array. Increment the array index each time so it's not saving and overwriting a prior element.
  1 Comment
vignesh R
vignesh R on 1 Apr 2015
I just went through the above,but i cant find what i am looking... Can you kindly tell me the changes in the highlighted coding to be made...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!