Image alignment with Vision

MLBoy
1 min readSep 26, 2020

--

You can use it for panoramic images and scene stabilization.

procedure

Create a registration request with the second image.

let request = VNTranslationalImageRegistrationRequest(targetedCIImage: image2, options: [:])

Perform with the first image.

let handler = VNImageRequestHandler(ciImage: image1, options: [:])
do {
try handler.perform([request])
} catch let error {
print(error)
}

The result is returned with a CGAffineTransform to align the second image with the first image.

guard let observation = request.results?.first as? VNImageTranslationAlignmentObservation else { return }
let alignmentTransform = observation.alignmentTransform

Based on the result, combine the two images.

image2 = image2.transformed(by: alignmentTransform)
let compositedImage = image1.applyingFilter("CIAdditionCompositing", parameters: ["inputBackgroundImage": image2])

important point

・ It tend to focus on prominent objects in the image.
・ Be careful of the orientation of the image taken by the camera. It is rotated 90 degrees.
Due to the above, it may behave unstable.

🐣

****

Please send your work request to this email

rockyshikoku@gmail.com

--

--

MLBoy
MLBoy

No responses yet