Insert PNG image into normal image

Normally, there is no problem, if we load two images in jpg formats, and insert one image to another as logo. But due to background and boarders, we need to insert png image. the output is attached
** how to handle png images.
As we know that png images have no backgroud, but once they are loaded in matlab, background turns into black. how to handle the background.
consider following image,
img1 = imread('1.jpg');
logo = imread('logo.png');
img1(1:size(logo,1), 1:size(logo,2), :) = logo;
imshow(img1)

5 comentarios

Guillaume
Guillaume el 18 de Sept. de 2019
"Normally, there is no problem, if we load two images in jpg formats,... But ... we need to insert png image."
The original format of the image does not matter at all for whatever it is you're doing in matlab. Whatever format it was, you get pixel intensities in matlab.
Now, it may be that your original code assumed that the images were RGB images of a certain class (probably uint8 MxNx3) and that you're now getting images of a different type (greyscale or indexed) or different class (uint16?) but that is unrelated to the storage format.
So, we need more detail about the actual images once loaded in matlab (size and class).
Rik
Rik el 18 de Sept. de 2019
The problem is still the same, as is the solution. If you want more explicit help, please attach the logo and image to your question.
Guillaume
Guillaume el 18 de Sept. de 2019
@rik, totally unrelated to the question at hand, how did you write your comment above? It has a smaller font than unusual, how did you achieve that? (It would help with diagnosing a current bug where some posts can't be edited).
Guillaume
Guillaume el 18 de Sept. de 2019
@king umar, is your question about compositing two images with one having associated transparency info (i.e alpha blending)?
Rik
Rik el 18 de Sept. de 2019
Editada: Rik el 18 de Sept. de 2019
@Guillaume I wrote that comment on Chrome in Android (just like this one). It does seem strange.

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 18 de Sept. de 2019

0 votos

If you want to prevent overwriting the underlying image for some pixels, you can use a logical mask to only overwrite some pixels.

1 comentario

king umar
king umar el 18 de Sept. de 2019
I have updated the question to be precise. Kindly, give your valueable feedback.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 18 de Sept. de 2019

Editada:

Rik
el 18 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by