Effacer les filtres
Effacer les filtres

How to superimpose images, making one of them transparent

2 vues (au cours des 30 derniers jours)
Julian
Julian le 5 Avr 2019
Hi everyone,
so i have a picture and i want to highlight some of the features in it. For example i would have an image of a table and i want to highlight a book that is just sitting there.
My approach at the moment is to use a tool to get the parameters of the book and then make me some sort of mask where the book is black and the rest of the image is still normal.
Now what i want is this black area to be for example a transparent light shade of red/green/blue (color doesnt matter). I used some of the code from here (https://de.mathworks.com/matlabcentral/answers/283698-how-to-merge-or-super-impose-two-images-in-matlab) to superimpose two images (original + mask) but then i only have the region of intrest (book) in black.
So my question would be: How do i get this region of interest transparent and in color. Do any of you have some ideas?
Thank you very much.
UPDATE: Okay i think i try my luck with the labeloverlay function. If you have any ideas regarding this, im also happy to hear them. Thanks

Réponses (1)

Bjorn Gustavsson
Bjorn Gustavsson le 5 Avr 2019
Perhaps something like this:
B = imread('peppers.png'); % Just to get a sample image
subplot(2,2,1)
imagesc(B)
[i1,j2] = ginput; % used to select a perimeter of an object...
[I1,J2] = meshgrid(1:size(B,1),1:size(B,2));
mask = inpolygon(J2,I1,i1([1:end,1]),j2([1:end,1]))'; % to create a mask
subplot(2,2,2)
imagesc(mask)
maskrgb = cat(3,mask,0*mask,0*mask); % Make an RGB-version of mask, here red
subplot(2,2,3)
imagesc((double(B)+128*maskrgb)/(256+128)) % weighted sum of images - scaled to between 0 and 1
subplot(2,2,4) % as this is what matlab expects for rgb-images in double format
imagesc((double(B)+512*maskrgb)/(256+512)) % different weighting
HTH

Produits


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by