- (UIImage *)normalizedImage:(UIImage *)sourceImage {
if (sourceImage.imageOrientation == UIImageOrientationUp)
return sourceImage;
UIGraphicsBeginImageContextWithOptions(sourceImage.size, NO, sourceImage.scale);
[sourceImage drawInRect:(CGRect){0, 0, sourceImage.size}];
UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return normalizedImage;
}