Real time Rgb2gray convert

1 次查看(过去 30 天)
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')

采纳的回答

Image Analyst
Image Analyst 2021-5-31
编辑:Image Analyst 2021-5-31
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 个评论
Image Analyst
Image Analyst 2021-6-2
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.
Zakaria Boussaid
Zakaria Boussaid 2021-6-2
thank you for this informative answer

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by