How to retrieval back the color in particular area from original image?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mei Synn Tan
le 17 Mar 2017
Modifié(e) : Mei Synn Tan
le 20 Mar 2017
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161826/image.jpeg)
13100.jpg
colorImage = imread('13100.jpg');
grayImage = rgb2gray(colorImage);
mserRegions = detectMSERFeatures(grayImage);
mserRegionsPixels = vertcat(cell2mat(mserRegions.PixelList));
mserMask = false(size(grayImage));
ind = sub2ind(size(mserMask), mserRegionsPixels(:,2), mserRegionsPixels(:,1));
mserMask(ind) = true;
figure;imshow(mserMask);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/161827/image.jpeg)
MSER mask
How to retrieve back the original color from 13100.jpg and paste into MSER mask (white area)?
0 commentaires
Réponse acceptée
Guillaume
le 17 Mar 2017
Much simpler:
maskedimage = immultiply(colorImage, repmat(mserMask, [1, 1, size(colorImage, 3)]));
imshow(maskedimage);
Note that if you just want to see if your mask is correct
imshowpair(colorImage, mserMask, 'blend');
may be more useful.
3 commentaires
Guillaume
le 18 Mar 2017
That's because you're only setting the red plane to 255, leaving the green and blue plane.
whiteMaskedImage(repmat(~mserMask, 1, 1, 3)) = 255;
would fix this.
Plus de réponses (1)
Image Analyst
le 17 Mar 2017
Try bsxfun():
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
1 commentaire
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!