2013-08-31 63 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