Skip to content

Instantly share code, notes, and snippets.

@sgl0v
Created June 2, 2021 19:19
Show Gist options
  • Save sgl0v/2a766f2e7b2538f4838e698c94a08842 to your computer and use it in GitHub Desktop.
Save sgl0v/2a766f2e7b2538f4838e698c94a08842 to your computer and use it in GitHub Desktop.
extension ImageColorizer {
private func colorize(image inputImage: UIImage) -> Result<UIImage, Error> {
do {
let inputImageLab = try preProcess(inputImage: inputImage) // ➊
let input = try colorizerInput(from: inputImageLab) // ➋
let output = try coremlColorizer(configuration: MLModelConfiguration()).prediction(input: input) // ➌
let outputImageLab = imageLab(from: output, inputImageLab: inputImageLab) // ➍
let resultImage = try postProcess(outputLAB: outputImageLab, inputImage: inputImage) // ➎
return .success(resultImage)
} catch {
return .failure(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment