Search code examples
matlabimage-processingmasking

How to make a partly transparent overlay on image in Matlab?


I have an image subdivided into slic superpixels. I'm using the gui to select some of these superpixels. Now I want to highlight the selected superpixels as transparent tiles.
However I only know how to either a) use an mask to suppress parts of the overlay image or b) how to set the entire overlay as tranparent.

a)

imshow(superPixelImage)
hold on;
h = imshow(overlayImage);
set(h,'AlphaData',overlayMask);

b)

imshow(superPixelImage)
hold on;
h = imshow(overlayImage);
set(h,'AlphaData',0.5);

Does someone know how to combine both such that the overlay is fully transparent on the non selected area and partly transparent on the marked superpixels?

Edit:
This is a beta-version of my matlab code that can be used to create semantic labels for an image database.

a)

b)


Solution

  • You can insert a matrix that match the size of your image to fill the 'AlphaData' parameter.

    imshow(superPixelImage)
    hold on;
    h = imshow(overlayImage);
    AlphaMatrix = (~im2bw(overlayImage)>0)*0.5 %creation of your AlphaMatrix.
    set(h,'AlphaData',AlphaMatrix);