Overlay two images on top of each other with rotation

8 visualizaciones (últimos 30 días)
Josh Tome
Josh Tome el 14 de Abr. de 2023
Comentada: DGM el 18 de Abr. de 2023
I have two images that I would like to overlay on top of each other. The first is an outline of a human. The second is the outline of an arm. I would like to first rotate the image of the arm to a specific angle (say 135 degree), and then overlay it on top of the image of the human outline. That way it looks like the human is reaching for something on a shelf above him.

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de Abr. de 2023
Read the images.
imcomplement the arm so that the dark outlines become bright and the bright outlines become dark. imrotate the complemented image. Now imcomplement that. You now have a rotated dark arm on a white background.
The reason to do the imcomplement before the rotation and then to complement back again, is that imrotate always adds a black background for parts of the new matrix that were originally outside the box. By making the background black, then rotating, then flipping colors, the effect is white background for the rotated arm.
Now, you have to figure out where exactly you want the rotated arm to go relative to the original. That would be a bit tricky to calculate unless you want to come up with some kind of mathematical formula such as "83% up from the bottom of the figure". It would probably be easier to just measure where you want it and use constants in the code.
Now figure out how high and wide an array you would need to join the body and the rotated arm together in one array. You will need to examine the rotation angle to figure out which side of the rotated arm is the attachment point to know whether the rotated arm goes to the left or the right of the body.
Once you have figured out the size needed for the composite image, pad the two images out to be the same size -- the padding will be different for the two images.
Now take min() of the padded images.
The result should be the composite image.
  4 comentarios
Josh Tome
Josh Tome el 18 de Abr. de 2023
Editada: Josh Tome el 18 de Abr. de 2023
Does the transparency of my arm image have to be done in another software, or can this be accomplished in MATLAB?
Before starting this post I did attempt to make the background of the arm image transparent in a different software (Paint 3D), but when I joined the images I ended up with black as the background of the arm image instead of it being transparent.
DGM
DGM el 18 de Abr. de 2023
I don't know what you did to create, read, or use the transparency, so I can't say why it was black. I can say that if you tried to read a transparent image via imread() with only a single output argument, then the transparent regions will be (typically) filled with black. Reading the alpha content requires using the multiple outputs as I showed. I don't know if that's what you're doing or not.
As far as doing it in MATLAB or externally, you could do it either way. I just did it externally.

Iniciar sesión para comentar.

Categorías

Más información sobre 3-D Volumetric Image Processing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by