Real time Rgb2gray convert
1 view (last 30 days)
Show older comments
Zakaria Boussaid
on 31 May 2021
Commented: Zakaria Boussaid
on 2 Jun 2021
hey guys i want to know if it is possible to convert in real time a RGB form video to a gray Form.
I tried to use rgbgray function and min function but i wasn't able to get what i want
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
%===============================================================================
%activate the integrated camera
web = webcam('HD Webcam')
set(web,'Resolution','640x480')
preview(web)
pause(5)
img = snapshot(web)
imshow(img)
%===============================================================================
% Read in a demo image.
%grayImage= min(originalRGBImage, [], 3); % Useful for finding image and color map regions of image.
grayImage = rgbgray(web); % Useful for finding image and color map regions of image.
imshow(grayImage)
clear('web')
0 Comments
Accepted Answer
Image Analyst
on 31 May 2021
Edited: Image Analyst
on 31 May 2021
You need to pass in the color image, not the webcam object. And you need to call rgb2gray(), not rgbgray().
rgbimage = snapshot(web)
grayImage = rgb2gray(rgbImage);
imshow(grayImage);
drawnow;
3 Comments
Image Analyst
on 2 Jun 2021
Not that I know of. You might be able to do it with the Image Acquisition Toolbox if you set the returned output space to RGB but I don't know if you can do that for the real-time LIVE webcam object. However you can do it not in real time by grabbing and image, converting it, and then displaying it like I showed. Not sure how much this would slow down the frame rate as compared to just letting it go full speed. And of course you can convert a non-real-time, saved video that is recalled from disk to gray scale very easily.
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!