converting binary to RGB problem?
Mostrar comentarios más antiguos
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
Respuestas (1)
Image Analyst
el 24 de Mzo. de 2014
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 comentarios
YUNUS
el 24 de Mzo. de 2014
YUNUS
el 24 de Mzo. de 2014
Image Analyst
el 24 de Mzo. de 2014
Try multiplying by 255:
rgbImage = cat(3, uint8(255*binaryImage), uint8(255*binaryImage), uint8(255*binaryImage));
YUNUS
el 24 de Mzo. de 2014
Image Analyst
el 24 de Mzo. de 2014
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?
Categorías
Más información sobre Image Preview and Device Configuration en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!