Upgrade to Pro — share decks privately, control downloads, hide ads and more …

顔写真メイクアップアプリの開発におけるプライバシー保護とコスト削減のための手法

Akio Itaya
September 03, 2023

 顔写真メイクアップアプリの開発におけるプライバシー保護とコスト削減のための手法

Akio Itaya

September 03, 2023
Tweet

More Decks by Akio Itaya

Other Decks in Programming

Transcript

  1. ৭Λ બ୒ 📸 ࡱӨ إͷ ෼ੳ 🔨 ฤू ϩ ʔ

    Χ ϧ ׬ ݁ إͷ෼ੳɾՃ޻Λ୺຤಺Ͱߦ͏ ϓϥΠόγʔอޢ
  2. ৭Λ બ୒ 📸 ࡱӨ إͷ ෼ੳ 🔨 ฤू ϩ ʔ

    Χ ϧ ׬ ݁ إͷ෼ੳɾՃ޻Λ୺຤಺Ͱߦ͏ ίετ࡟ݮ
  3. Vision Framework Apply computer vision algorithms to perform a variety

    of tasks on input images and video. https://developer.apple.com/documentation/vision
  4. إͷ෼ੳ final class ViewModel { init() { let mlModel =

    try! FaceParsing().model } 
 } MLModel ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  5. إͷ෼ੳ final class ViewModel { init() { let mlModel =

    try! FaceParsing().model let coreMLModel = try! VNCoreMLModel(for: mlModel) } 
 } MLModel VNCoreMLModel ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  6. إͷ෼ੳ final class ViewModel { init() { let mlModel =

    try! FaceParsing().model let coreMLModel = try! VNCoreMLModel(for: mlModel) let request = VNCoreMLRequest(model: coreMLModel) request.imageCropAndScaleOption = .scaleFill } 
 } MLModel VNCoreMLModel VNCoreMLRequest ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  7. إͷ෼ੳ final class ViewModel { private let faceImage = CIImage(image:

    UIImage(named: “face")!)! init() { 
 … } 
 } CIImage ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  8. إͷ෼ੳ final class ViewModel { private let faceImage = CIImage(image:

    UIImage(named: “face")!)! init() { 
 … let requestHandler = VNImageRequestHandler(ciImage: faceImage) } 
 } CIImage VNImageRequestHandler ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  9. إͷ෼ੳ final class ViewModel { private let faceImage = CIImage(image:

    UIImage(named: “face")!)! init() { 
 … let requestHandler = VNImageRequestHandler(ciImage: faceImage) try! requestHandler.perform([request]) } 
 } CIImage VNImageRequestHandler VNCoreMLRequest ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  10. VNCoreMLRequest إͷ෼ੳ final class ViewModel { private let faceImage =

    CIImage(image: UIImage(named: "face")!)! init() { … let requestHandler = VNImageRequestHandler(ciImage: faceImage) try! requestHandler.perform([request]) let result = request.results!.first as! VNCoreMLFeatureValueObservation } 
 } VNCoreMLFeatureValueObservation ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  11. إͷ෼ੳ final class ViewModel { private let faceImage = CIImage(image:

    UIImage(named: "face")!)! init() { … let requestHandler = VNImageRequestHandler(ciImage: faceImage) try! requestHandler.perform([request]) let result = request.results!.first as! VNCoreMLFeatureValueObservation let multiArray = result.featureValue.multiArrayValue! } 
 } MLMultiArray ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢ VNCoreMLRequest VNCoreMLFeatureValueObservation
  12. إͷ෼ੳ final class ViewModel { private let multiArray: MLMultiArray private

    let faceImage = CIImage(image: UIImage(named: "face")!)! init() { … let requestHandler = VNImageRequestHandler(ciImage: faceImage) try! requestHandler.perform([request]) let result = request.results!.first as! VNCoreMLFeatureValueObservation multiArray = result.featureValue.multiArrayValue! } 
 } ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢ MLMultiArray VNCoreMLRequest VNCoreMLFeatureValueObservation
  13. CIColorCrossPolynomial The properties you use to con fi gure a

    color cross-polynomial fi lter https://developer.apple.com/documentation/coreimage/cicolorcrosspolynomial 14
  14. CIColorCrossPolynomial https://note.com/yogox/n/n7aa72d268144#aXmbf ɹ: ܎਺
 ɹ: ೖྗըૉͷ੺੒෼஋
 ɹ: ೖྗըૉͷ྘੒෼஋
 ɹ: ೖྗըૉͷ੨੒෼஋

    f(r,g,b)=k_0r+k_1g+k_2b+k_3r^2+k_4g^2+k_5b^2+k_6rg+k_7gb+k_8br+k_9
 https://sundryst.com/convenienttool_math/drawexpression.html ग़ྗըૉͷ֤৭੒෼஋
  15. CIColorCrossPolynomial let redArray: [CGFloat] = [2, 2, 2, 0, 0,

    0, 0, 0, 0, 0.2] let redVector = CIVector(values: redArray, count: redArray.count)
  16. CIColorCrossPolynomial let redArray: [CGFloat] = [2, 2, 2, 0, 0,

    0, 0, 0, 0, 0.2] let redVector = CIVector(values: redArray, count: redArray.count) let editedCIImage = CIFilter( name: "CIColorCrossPolynomial", parameters: ["inputRedCoefficients": redVector] )!.outputImage! ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  17. CIColorCrossPolynomial let redArray: [CGFloat] = [2, 2, 2, 0, 0,

    0, 0, 0, 0, 0.2] let redVector = CIVector(values: redArray, count: redArray.count) 
 let image = CIImage(image: UIImage(named: "color_test")!)! let editedCIImage = CIFilter( name: "CIColorCrossPolynomial", parameters: [ kCIInputImageKey: ciImage, "inputRedCoefficients": redVector ] )!.outputImage! ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  18. CIColorCrossPolynomial let redArray: [CGFloat] = [2, 2, 2, 0, 0,

    0, 0, 0, 0, 0.2] let redVector = CIVector(values: redArray, count: redArray.count) 
 let image = CIImage(image: UIImage(named: "color_test")!)! let editedCIImage = CIFilter( name: "CIColorCrossPolynomial", parameters: [ kCIInputImageKey: ciImage, "inputRedCoefficients": redVector ] )!.outputImage! let context = CIContext() let cgImage = context.createCGImage(editedCIImage, from: editedCIImage.extent)! ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢
  19. let editedCIImage = CIFilter(name: "CIColorCrossPolynomial",…)!.outputImage! 
 
 let upperLipCGImage =

    multiArray.cgImage(…, outputType: FaceType.upperLip)! 
 let upperLipCIImage = CIImage(cgImage: …).resize(as: faceImage.extent.size) ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢ όʔνϟϧϝΠΫʹ௅ઓ
  20. let editedCIImage = CIFilter(name: "CIColorCrossPolynomial",…)!.outputImage! 
 
 let upperLipCGImage =

    multiArray.cgImage(…, outputType: FaceType.upperLip)! 
 let upperLipCIImage = CIImage(cgImage: …).resize(as: faceImage.extent.size) 
 
 let compositedUpperLipImage = CIFilter( name: "CIBlendWithMask", parameters: [ kCIInputImageKey: editedCIImage, kCIInputBackgroundImageKey: faceImage, kCIInputMaskImageKey: upperLipCIImage ] )!.outputImage! ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢ όʔνϟϧϝΠΫʹ௅ઓ
  21. let editedCIImage = CIFilter(name: "CIColorCrossPolynomial",…)!.outputImage! 
 
 let upperLipCGImage =

    multiArray.cgImage(…, outputType: FaceType.upperLip)! 
 let upperLipCIImage = CIImage(cgImage: …).resize(as: faceImage.extent.size) 
 
 let compositedUpperLipImage = CIFilter( name: "CIBlendWithMask", parameters: [ kCIInputImageKey: editedCIImage, kCIInputBackgroundImageKey: faceImage, kCIInputMaskImageKey: upperLipCIImage ] )!.outputImage! 
 
 let context = CIContext() let cgImage = context.createCGImage( 
 compositedUpperLipImage, 
 from: compositedUpperLipImage.extent 
 )! ίʔυ؆ུԽͷͨΊʹڧ੍ΞϯϥοϓΛଟ༻͍ͯ͠·͢ όʔνϟϧϝΠΫʹ௅ઓ