简体   繁体   中英

MATLAB Video: how to use 'readFrame' output for 'imbinarize' function?

I'm doing the following:1. Loading the original video 2. converting the video to black and white 3. saving it to a new avi file. Repeating for each frame.

;

However I got the the following error:

Expected I to be two-dimensional

Why am I getting this error message? Isn't a frame going to be two-dimensional?

The image from your video is an RGB image so it is M x N x 3 and imbinarize only accepts 2D inputs. In order to process your image, you'll want to first convert it from RGB to grayscale using rgb2gray

img = rgb2gray(readFrame(reader));

Also, since the output of imbinarize is logical , you'll need to first convert it to a double prior to writing it to the output video

writeVideo(writer, double(BW));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM