Displaying a png image without the background

user3531992

http://sweetclipart.com/multisite/sweetclipart/files/sunglasses_black.png

I have read the png image in MATLAB using [X,map,alpha]=imread('...','png'). Now I want to place this png image on another image. But I want the background color of the read png not to be shown. In the link I want the sunglasses alone to be shown without the 'white' background (Background is another image).

Rafael Monteiro

You can do it like this:

% Image with alpha channel
[glasses, ~, alpha] = imread('http://sweetclipart.com/multisite/sweetclipart/files/sunglasses_black.png');

% OPTIONAL: Let's rescale it (it's very big!)
glasses = imresize(glasses, 0.1);
alpha = imresize(alpha, 0.1);

% An image of a person (let's put the glasses on the person).
person = imread('http://cinemacao.com/wp-content/uploads/2013/12/Scarlett-CAPA-2.jpg');

% Lets make the alpha MxNx3 (so we can combine it with the RGB channels).
alpha = repmat(alpha, [1 1 3]);

% And convert everything from uint8 to double (to avoid precision issues).
glasses = im2double(glasses);
alpha = im2double(alpha);
person = im2double(person);

% Final image

% Let x,y be the top-left coordinates where we'll put the glasses.
x = 440;
y = 450;

% Let's combine the images.
img3 = person;
img3(y:y+size(glasses,1)-1, x:x+size(glasses,2)-1, :) = ...
    glasses .* alpha + ...
    person(y:y+size(glasses,1)-1, x:x+size(glasses,2)-1, :) .* (1 - alpha);

% An display the result.
imshow(img3);

Result: enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

GUI with Tkinter - PNG background image not displaying?

From Dev

Why is this not displaying my background image title.png?

From Dev

PNG Image not displaying

From Dev

MFC displaying png with transparent background

From Dev

visualforce background image not displaying

From Dev

Body background image not displaying

From Dev

background image not displaying correctly

From Dev

Body background image not displaying

From Dev

Background Image is not displaying in Div

From Dev

Background Image not Displaying in Chrome

From Dev

CSS Background Image not displaying on mobile

From Dev

Background image size is not displaying on firefox

From Dev

background image not displaying css/html

From Dev

Background image not displaying for email in html

From Dev

Background image not displaying on mobile devices

From Dev

background-image not displaying on ios

From Dev

CSS: div with background image not displaying

From Dev

Local background image not displaying in html

From Dev

Upload png image black background

From Dev

ImageButton with PNG image with transparent background as background

From Dev

Background image not displaying and text not in line by image

From Dev

Image without background on winform

From Dev

Image saved but without background

From Dev

blur without background image

From Dev

SVG background image isn't displaying

From Dev

Displaying a background image on a UWP ink canvas

From Dev

UIButton not displaying background image on device or simulator

From Dev

Hover, effecting other elements and displaying background image

From Dev

Background image not displaying on old IE versions

Related Related

HotTag

Archive