假设我们有一个像素被标记为1
和2
的图像。我们如何在MATLAB
中执行以下操作?
1s
和2s
的位置转换为二进制掩码感谢。
答案 0 :(得分:1)
示例:
% 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)