I am not 100% sure, I understand your problem, but here comes one suggestion:
Suppose rgbIm is your RGB image and bwIm is your binary image;
You can try to โdeployโ your binary image to โ3Dโ (so that its size matches the original RGB image) with the following line of code:
bwImAux = bwIm(:,:,[1 1 1]);
And then do a simple multiplication to โeliminateโ all the pixels that are not in the binary image:
rgbImNew = rgbIm.*bwImAux;
Hope this helps.
fnery source share