Say that we have an image which pixels were labeled 1
and 2
. How can we do the following in MATLAB
?
1s
and 2s
into binary masksThanks.
Example:
% some RGB image
img = im2double(imread('peppers.png'));
[h,w,~] = size(img);
% lets create some random labels. I'm simply dividing into two halves,
% where upper half is labeled 1, and lower half labeled 2
labels = [ones(h/2,w)*1; ones(h/2,w)*2];
% compute masks and filter image using each
img1 = bsxfun(@times, img, labels==1);
img2 = bsxfun(@times, img, labels==2);
% show result
subplot(121), imshow(img1)
subplot(122), imshow(img2)