converting binary to RGB problem?

hi i implemented the background subtraction using frame difference technique,it works but last output of program is binary form(1-0), but i want to convert it to rgb form,is it possible?, can anyone help me? here my code;
% %%background subtraction-%%
%%camera options
vid = videoinput('winvideo', 1, 'YUY2_640x480');
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval =5;
start(vid)
%%count elements
sum_frames=0;
count_frames=0;
while(vid.FramesAcquired<=50)
I = getsnapshot(vid);
Im=im2double(I);
imR=squeeze(Im(:,:,1));
imG=squeeze(Im(:,:,2));
imB=squeeze(Im(:,:,3));
imBinaryR=im2bw(imR,graythresh(imR));
imBinaryG=im2bw(imR,graythresh(imG));
imBinaryB=im2bw(imR,graythresh(imB));
imBinary=imcomplement(imBinaryR&imBinaryG&imBinaryB);
c=im2bw(imBinary);
imshow(c)
se=strel('disk',7);
imClean=imopen(imBinary,se);
imClean=imfill(imClean,'holes');
imClean=imclearborder(imClean);
sum_frames=sum_frames+imClean;
count_frames=count_frames+1;
end
mean_frames=sum_frames/count_frames;
subplot(1,2,1);
imshow(mean_frames);
while(vid.FramesAcquired<=100)
I = getsnapshot(vid);
Im=im2double(I);
imR=squeeze(Im(:,:,1));
imG=squeeze(Im(:,:,2));
imB=squeeze(Im(:,:,3));
imBinaryR=im2bw(imR,graythresh(imR));
imBinaryG=im2bw(imR,graythresh(imG));
imBinaryB=im2bw(imR,graythresh(imB));
imBinary=imcomplement(imBinaryR&imBinaryG&imBinaryB);
diff_frames=imBinary-mean_frames;
subplot(1,2,2);
imshow(diff_frames);
end
stop(vid);
flushdata(vid);
clear all

回答 (1 件)

Image Analyst
Image Analyst 2014 年 3 月 24 日

0 投票

Why do you want to turn a binary image into an RGB image? And what would be in each channel? The same binary image? If so, do this (though I don't know why you'd want to):
rgbImage = cat(3, uint8(binaryImage), uint8(binaryImage), uint8(binaryImage));

5 件のコメント

YUNUS
YUNUS 2014 年 3 月 24 日
im working on the hand detection and i used binary technique to avoid light intensity problem
YUNUS
YUNUS 2014 年 3 月 24 日
i tried your suggestion but it didnt work, all the screen was black
Image Analyst
Image Analyst 2014 年 3 月 24 日
Try multiplying by 255:
rgbImage = cat(3, uint8(255*binaryImage), uint8(255*binaryImage), uint8(255*binaryImage));
YUNUS
YUNUS 2014 年 3 月 24 日
dont work
Image Analyst
Image Analyst 2014 年 3 月 24 日
does work. Works for me. Try this:
z = peaks(300); % Make sample data.
binaryImage = z > 2; % Create a binary image
rgbImage = cat(3, uint8(255*binaryImage), uint8(255*binaryImage), uint8(255*binaryImage));
imshow(rgbImage);
Does that work for you? (It will). So what are you doing differently? How did you change the code?

サインインしてコメントする。

質問済み:

2014 年 3 月 24 日

コメント済み:

2014 年 3 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by