Reputation: 17
I am working on Simulink to develop my algorithm. I have a video stream with dimensions 640x360. I am trying to extract region of interest (ROI) from each frame. However, my video turns into grayscale when I use the following code:
MATLAB Function Block which I am using for the ROI extraction:
function y = fcn(u)
%some more code
width = 639;
height = 210;
top = 150;
left = 1;
y = u(top:top+height, left:left+width);
Upvotes: 0
Views: 411
Reputation: 5822
Solution
Change the last line as follows:
y = u(top:top+height, left:left+width,:);
Explanation
The dimensions of an RGB image are actually mxnx3. The m and n are the image height and width, and there are 3 channels: red, green and blue.
when you perform a cropping of an RGB image, it should be performed on each channel separately. You can achieve that by using my code example above.
Upvotes: 1