When compositing images with masks, calculate the aspect ratio so that it does not exceed
When synthesizing two images with different aspect ratios by mask
, the images may protrude.

You have to scale the image so that it doesn’t
stick out, but when You have a Front Image and a Background Image to composite There is a combination of…
Which is longer, horizontal or vertical, of the Front Image?
Which is longer, horizontal or vertical, of the Background Image?
Which is longer, Front Image vertical or Background Image vertical?
Which is longer, the side of the Front Image or the side of the Background Image?
and it is troublesome to describe all the patterns so that there is no protrusion.
At first, I thought, “I should fit on the shorter side,” and set the scale, but only the side was sticking out.
If you simply combine two images,
CIMinimumCompositing
will calculate it so that it does not protrude, but in
the case of a mask image, there is no filter that calculates it, and it is simply combined with the coordinates and size of the image. To.
Therefore, in order to cover all the patterns and combine the FrontImage so that it does not protrude from the BackgroundImage
and is displayed as large as possible, the following scale calculation should be performed.

Image that fits properly
🐣
I’m a freelance engineer.
Work consultation
Please feel free to contact us with a brief development description.
rockyshikoku@gmail.com
I am making an app that uses Core ML and ARKit.
We send machine learning / AR related information.