I was scrolling through some answers of the same issue and got the following
C = num2cell(YourImage);
C(~YourImage) = {{}};
This should give a cell array in which there are empty cells ("nothing") where the background was, and cells containing 1 where the foreground was.And
imagesc(YourImage, 'AlphaData', YourImage)
colormap(gray)
set(gca, 'color', 'none')
to set the Region of interest visible,i did try it myself and didn't get a result,What am i doing wrong and the correct way to use this code.
Example of image with black background: