2013-08-31 112 views

回答

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) 

images

+0

感谢您的答复。关于'img1 = bsxfun(@times,img,labels == 1);',你是说在这里乘以'img'与值为'1'的像素?它在这里如何是一个二进制掩码? – Simplicity

+1

@Simplicity:'labels == k'将创建一个逻辑矩阵,对于标签为'k'的位置创建'true',否则创建'false'。然后我将这个蒙版乘以图像的像素(元素明智)。乘以1保持原始值,乘以零将使像素为零。 “bsxfun”用于在R,G,B图像通道的第三维上广播遮罩。 – Amro

+0

对不起,关于'subplot',我回到了文档,但不明白'121'和'122'代表什么值? – Simplicity