how to create a video after an edge detection for loop

2 views (last 30 days)
Hi all!
Hopefully you can help, I'm having trouble getting this code to work. My aim is to apply edge detection to a video of cells (this part works and I am happy with it) and then have the frames of the resulting edge detection become a new .avi video in itself (that I can play just like the previous .avi file). I have tried a number of methods outside the for loop I created for the edge detection but none of it seems to work. The code is below:
function Vid_Edge_Detection_flourescent
v = VideoReader('VID00126.AVI');
n = v.NumFrames;
for i = 1:n
I0 = read(v,i);
I1 = im2bw(I0,graythresh(I0)-0.03);
I2 = bwareaopen(I1,50);
I3 = edge(I2);
II = imfuse(I0,I3);
imshow(II,'initialmagnification','fit')
pause(0.1)
end
open(v);
w = VideoWriter('Flourescent00126.AVI');
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z)
frame = getframe(gcf);
writeVideo(v,frame);
end
close(v);
If anyone can help that would be amazing! I cant share the .avi as it is above 5mb but the general principle goes. Id like to have a new resulting avi file that the edge detection function has changed. Thanks in advance!

Accepted Answer

Image Analyst
Image Analyst on 4 Jul 2020
You're not writing the edge image out, either to a saved image file or the video. See my attached demos -- they show you how to do it. In particular the movie_Canny makes a movie of the edges.
  4 Comments
Ben Timm
Ben Timm on 7 Jul 2020
Edited: Ben Timm on 7 Jul 2020
Once again thanks for the help! I didn't realise the try block did that so the heads up was appreciated.
I ran your test.m file after reading through it and there were a couple of issues I found which I have seemingly sorted. That is until the most recent one where this error occurs:
"
Error using imread>get_full_filename (line 566)
File "/Desktop/Matlab Files/Videos/Movie Frames from VID00123/Frame0001.png" does not exist.
Error in imread (line 375)
fullname = get_full_filename(filename);
Error in test1 (line 238)
thisFrame = imread(outputFullFileName);
"
I noticed the produced avi was 0mb big despite the processing of edge detection working seemingly perfect. I figure the real problem is before line 238, possibly around 180 but after searching online and .doc'ing it, Ive come up with nothing as of yet..
Ben Timm
Ben Timm on 9 Jul 2020
I figured it out! For anyone that needs help with this in the future, please see the attached doc.
Thank you again for the assistance Image Analyst!
-Ben

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!