Overlay two images on top of each other with rotation
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
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
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.
Siehe auch
Kategorien
Mehr zu 3-D Volumetric Image Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!