Correlation of 300 frames

Please provide a solution for how to find a correlation value for 300 frames by considering its pixel values and stored it in array or some memory space. For example if we found correlation of first and second image, we will get one correlation value like 0.9. Then we should find a correlation between second and third image, third and fourth, etc. Like this how to find for 300 adjacent images.

 Accepted Answer

You can use the 2-D correlation coefficient function
corr2(A,B)
Depending on how the data for your frames are stored, you can write a for loop to compare consecutive pairs.
For example, if you had a 3D array of frames called frameArray that is 512x512x300 :
imageCorrelation=zeros(299,1)
for i=1:299
imageCorrelation(i)=corr2(frameArray(:,:,i),frameArray(:,:,i+1))
end

16 Comments

I'm having frame 0 to frame 299 in single folder
Are you asking how to read the frames into matlab? I don't know what your filenames look like, but you should try the imread function first:
frameArray=zeros(512,512,300)
for i=1:300
frameArray(:,:,i)=imread(['frame' num2str(i-1) '.tif'])
end
Edit: I just realized you want 0 to 299 instead of 1 to 300. This should work then. Use this to import the frames and run the corr2 for loop in the main answer to get the coefficients. Just modify the filenames appropriately.
yea first i should read the 300 frames from frame0 to frame 299 which is stored in a folder... Then i should calculate the correlation of those 300 frames and that correlation values should be store in array sir
for corr2() which are the parameters i should pass.
Because frame0 to frame299 are in single folder.... Should I pass the whole folder... If i should can u please say how to pass
Can u provide complete code please
Give me the name of your folder and an example name of your file.
folder name is images... file name is frame0
What's the filetype?
frame0.jpg
Okay, so if you're running in a directory containing the subdirectory "images", you can run the full code as:
frameArray=zeros(512,512,300)
for i=1:300
frameArray(:,:,i)=imread(['images/frame' num2str(i-1) '.jpg'])
end
imageCorrelation=zeros(299,1)
for i=1:299
imageCorrelation(i)=corr2(frameArray(:,:,i),frameArray(:,:,i+1))
end
Thank you so much sir
sir if there are 298 images... which value should be changed sir??
I assume you're going from frame0 to frame297 now? Just modify the matrix sizes and for loop indices appropriately:
frameArray=zeros(512,512,298)
for i=1:298
frameArray(:,:,i)=imread(['images/frame' num2str(i-1) '.jpg'])
end
imageCorrelation=zeros(297,1)
for i=1:297
imageCorrelation(i)=corr2(frameArray(:,:,i),frameArray(:,:,i+1))
end
No sir frame0 to frame298
Please change and send the code sir it's more important for me sir please
Please can u solve this below error sir... I'm getting an error like this...
Subscripted assignment dimension mismatch.
Error in matlab1 (line 3)
frameArray(:,:,i)=imread(['images/frame' num2str(i-1) '.jpg'])

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!