Soccertrash Soccertrash - 4 years ago 132
iOS Question

Load UIImage to float array for DeepLearningKit usage

I'd like to use the DeepLearningKit for iOS. I want to use UIImage objects to be classified. The sample application only uses a float array loaded from a json file. Thus I have to create the bitmap representation of the UIImage as a float array and use this for the classify-method.

Can anybody help me on that? Is there a way to create a bitmap representation for UIImage? Moreover I have to swap the channels from RGB to BGR.

Thank you

Answer Source

Have added an extension to UIImage that allows setting and getting RGB(A) pixels directly - key methods:

public func setPixelColorAtPoint(point:CGPoint, color: RawColorType) -> UIImage? 
func getPixelColorAtLocation(point:CGPoint)->UIColor?

where RawColorType is defined as

public typealias RawColorType = (newRedColor:UInt8, newgreenColor:UInt8, newblueColor:UInt8,  newalphaValue:UInt8)

This way you should be able to convert back and forth between bitmap representation and UIImage. Wrote a blog post that gives some more context:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download