problem in getting grayscale image from rgb image
1 view (last 30 days)
Show older comments
Hi,
In this program when converting background image(BG) to grayscale, I'm getting a problem, but not with current image im. The update_background function is attached here please help me.
clc;
clear all
close all;
vid = mmreader('hall_monitor.mpg'); Nframe = vid.NumberOfFrames;
L = 5;
%%WEBCAM
delete(imaqfind)
% vid=videoinput('winvideo',1,'YUY2_320x240');
vid=videoinput('winvideo',1);
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1 );
set(vid,'TriggerRepeat', Inf);
% start(vid);
% vid = videoinput('winvideo',1);
% View the default color space used for the data — The value of the ReturnedColorSpace property indicates the color space of the image data.
color_spec=vid.ReturnedColorSpace;
% Modify the color space used for the data — To change the color space of the returned image data, set the value of the ReturnedColorSpace property.
if ~strcmp(color_spec,'rgb')
set(vid,'ReturnedColorSpace','rgb');
end
start(vid)
pause
%%Detect background
trigger(vid);
im=getdata(vid,1); % Get the frame in im
[nr nc nm ] = size(im);
nf = L;
frames = zeros(nr,nc,nm,L);
for ii = 1:L
% ii;
trigger(vid);
im=getdata(vid,1);% Get the frame in im
% im=rgb2hsv(im);
% figure, imshow(im);
G = fspecial('gaussian',[9 9],2);
%# Filter it
im = imfilter(im,G,'same');
% end
% figure,imshow(im)
frames(:,:,:,ii) = im;
end
% BG =updateBG( frames);
BG = update_background(frames);
BG= rgb2gray(BG);
% raj=BG(:,:,1);
% toc
% clear frames
subplot(231)
imshow(uint8(BG))
title('BACKGROUND')
T=5;
%%Moving object Detection
for ii = 1:150
tic
trigger(vid);
im=getdata(vid,1); % Get the frame in im
% im=rgb2hsv(im);
G = fspecial('gaussian',[9 9],2);
%# Filter it
im = imfilter(im,G,'same');
im= rgb2gray(im);
% subplot(131)
subplot(232)
imshow(im)
title(['Frame = ' num2str(ii)])
end
0 Comments
Answers (0)
See Also
Categories
Find more on Point Grey Hardware 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!