How can i vectorize rgb2gray function ?

Sir, I'm facing a problem that matlab are very slow against for loop and i found vectorization will solve this problem.
I readed the "Vectorization document" already and got those example but in my case, i cann't vectorize my code.
the code is very simple. just try to convert RGB video to grayscale video without for loop.
vid = VideoReader('dataset\video\terrace1-c3.avi'); %some video
no = 50;
frames = read(vid, [1 no]); % 4-dimension matrix RGB color [R G B frame]
for i = 1:no;
grayFrames(:,:,i) = rgb2gray(frames(:,:,:,i));
end
I know multiplying 299 587 114 to matrix will make the same result but for longrun, i have to know how to vectorize any matlab function.
please give me some example.

Answers (0)

Products

Asked:

on 29 Nov 2018

Edited:

on 29 Nov 2018

Community Treasure Hunt

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

Start Hunting!