How to multiply binary image and rgb image in matlab?

21 vues (au cours des 30 derniers jours)
bay rem le 3 Mar 2016
I have a binary image which is the segmented form of another color image . As you know , a binary image is 2-d but an rgb image is 3-d , how want to multiply them together ? i tried this code but an error is generated: function skinCrop(bwSkin,colorSkin)
for i = 1:size(colorImage,1)
for j = 1:size(colorImage,2)
if bwImage(i,j) == 0
colorImage(i,j,:) = 0;
end
end
end
imshow(colorImage);
end
and here there is the error:
Index exceeds matrix dimensions.
3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
bay rem le 3 Mar 2016
its the complete error,thank you, i'll check the sizes
Sanzhar Askaruly le 31 Oct 2018
I tried your code, it worked, so it seems sizes are the problem.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst le 3 Mar 2016
There are several ways to do what you want, though bsxfun() is the method I usually use (though it's more cryptic than the .* straightforward method). I first learned that from Sean DeWolski of the Mathworks. However, if bwImage is not the same integer type as colorImage, you will have to modify it.
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, colorImage, cast(bwImage, 'like', colorImage));
If they're already both the same data type, then having cast in there won't hurt so I always put it in there regardless.
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Plus de réponses (1)

Jan le 3 Mar 2016
if both images have the same number of pixels:
result = colorImage .* cat(3, bwImage, bwImage, bwImage);
7 commentairesAfficher 5 commentaires plus anciensMasquer 5 commentaires plus anciens
Image Analyst le 19 Mar 2018
swathi le 19 Mar 2018
Thank you very much sir. It worked. Can I extend me query a little more, if you don mind(Sorry for it). Can I use this code to remove object from all frames in which it(or part of it) is visible? I need some advice, as I am working 1st time on videos. Thanks in advance

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by