Q: Swift: Convert Grayscale Image to CVPixelBuffer containing disparity I have a gray scale image of depth data that has been upsampled from its original resolution. I'm stuck as to how I can convert the pixel values of the upscaled depth image (r,g,b) to a float. 
Is there a way to convert the level of whiteness of a pixel a float value?
Is there anyway I could convert the CVPixelBufferFormatTypes of the CVPixelBuffer associated with the image?
Said another way, is there a way to convert the pixel buffer of a gray scale image into CVpixelbuffer containing disparity floats?
I use the following code to extract the cvpixelbuffer from a cgimage representation of the upsampled depth data:-
func pixelBuffer() -> CVPixelBuffer? {

    let frameSize = CGSize(width: self.width, height: self.height)

    //COLOR IS BGRA
    var pixelBuffer:CVPixelBuffer? = nil
    let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(frameSize.width), Int(frameSize.height), kCVPixelFormatType_32BGRA , nil, &pixelBuffer)

    if status != kCVReturnSuccess {
        return nil

    }

    CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags.init(rawValue: 0))
    let data = CVPixelBufferGetBaseAddress(pixelBuffer!)
    let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
    let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Big.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue)
    let context = CGContext(data: data, width: Int(frameSize.width), height: Int(frameSize.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!), space: rgbColorSpace, bitmapInfo: bitmapInfo.rawValue)


    context?.draw(self, in: CGRect(x: 0, y: 0, width: self.width, height: self.height))

    CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))

    return pixelBuffer
}

