Overlay two images on top of each other with rotation

12 Ansichten (letzte 30 Tage)
Josh Tome
Josh Tome am 14 Apr. 2023
Kommentiert: DGM am 18 Apr. 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.

Antworten (1)

Walter Roberson
Walter Roberson am 14 Apr. 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 Kommentare
Josh Tome
Josh Tome am 18 Apr. 2023
Bearbeitet: Josh Tome am 18 Apr. 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 am 18 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by