title: Convert color video to grayscale video in MATLAB
body: <p>I am trying to do some operations on color video in MATLAB however, I am facing 2 problems:</p>
  
  <ul>
  <li><p>I am getting an error while converting color video to grayscale video. I mean I need to convert color video to grayscale video and write it back to .avi file</p></li>
  <li><p>How can I perform some operation (say edge detection) on grayscale frames (extracted from color video) and then can write back the result of edge detection in .avi video format?</p></li>
  </ul>
  
  <p>My incomplete code (which consist of color format conversion) is as follows:</p>
  
  <pre><code>vid = VideoReader('Big_buck_bunny_480p_Cut.avi');
  numImgs = get(vid, 'NumberOfFrames');
  frames = read(vid);
  for i=1:numImgs
    frames(:,:,:,i)=rgb2gray(frames(:,:,:,i));
  end
  </code></pre>
  
  <p>Any pointer to fix these two problems?</p>