I have an RGB image (M x N x 3 matrix) in MATLAB that I read in. I also have a Binary mask (M x N matrix) for the image, which is simply 0 for some region of interest and 1 ever
You are misusing imfilter()
there. Imfilter is used for linear filter operations, not for masking or thresholding. Better do this:
z = image; % image() is also a function.
% Overwriting this name should be avoided
% Request user polygon for ROI
bw = roipoly(z);
% Create 3 channel mask
mask_three_chan = repmat(bw, [1, 1, 3]);
% Apply Mask
z(~mask_three_chan) = 0;
% Display
imshow(z);