BTW, this is a very good tutorial on raw image processing:
https://developer.apple.com/wwdc21/10160
Post
Replies
Boosts
Views
Activity
I have been running different tests with the new CiRawFilter class and it seems to work well for me on macOS 12.3.1 in a Playground in Xcode 13.3.1.
I tried the code with both a raw photo from my Canon Camera (CR2 format) and a raw photo from my iPhone 11 (DNG format). I do not have access to ProRaw photos, though.
BTW, I noticed that your rawFilter is not optional. Maybe this is the issue?
Here my code:
import Cocoa
import Foundation
import CoreImage
import SwiftUI
// Path to locally stored raw image, not ProRaw, from an iPhone 11
let rawimgpath = "/...path.../IMGAGE.dng"
let rawimgurl = URL(fileURLWithPath: rawimgpath)
// Initialising the CiRAWFilter with URL
let rawfilter = CIRAWFilter(imageURL: rawimgurl)
// Creating a CI Image
let rawimg = rawfilter?.outputImage
// Creating a CG Image
let context = CIContext()
let rawcgimg = context.createCGImage(rawimg!, from: rawimg!.extent)
let rawuiimg = Image(decorative: rawcgimg!, scale: 1.0)
// Printing the properties of the filter... this should also show your Gammut Mapping
let rawFltProps = rawfilter?.properties
// Printing the properties of the image...
let rawImgProps = rawimg?.properties
// This does not cause an error
let isgammutMappingEnabled = rawfilter?.isGamutMappingEnabled // Returns (Optional)true
// Note: The Ci rawfilter is always optional with the "?" !
PS: Please, use the "Code Block" feature in the editor for better readability of your code. Makes things a little easier ;-).
Hi, I am having exactly the same issue. Did you find a solution?
I have the raw data from a camera sensor with 14bit/pixel with an RGGB color-filter array (CFA).
I tried so many things to convert this to a color image, while letting iOS/Swift take care of the demosaicing. It obviously can do it. No need for me to program the de-bayering myself and probably doing a poor job at it compared to what iOS could do.
Here is my code, which only gets me black and white (or better grayscale) images:
let dummyImg = UIImage(systemName: "star.fill")?.cgImage
// imgRawData is a [UInt16] array
var pixelBuffer: CVPixelBuffer?
let attrs: [ CFString : Any ] = [ kCVPixelBufferCGImageCompatibilityKey : kCFBooleanTrue as Any,
kCVPixelBufferCGBitmapContextCompatibilityKey : kCFBooleanTrue as Any,
kCVPixelBufferPixelFormatTypeKey : "rgg4" ]
CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, kCVPixelFormatType_14Bayer_RGGB, &imgRawData, 2*width, nil, nil, attrs as CFDictionary, &pixelBuffer)
let ciimg = CIImage(cvImageBuffer: pixelBuffer!)
let context: CIContext = CIContext.init(options: [ CIContextOption(rawValue: "workingFormat") : CIFormat.RGBA16 ] )
guard let cgi = context.createCGImage(ciimg, from: ciimg.extent, format: CIFormat.RGBA16, colorSpace: CGColorSpace(name: CGColorSpace.sRGB), deferred: false)
else { return dummyImg! }
I also tried this more direct approach with VideoTools.... it just returns nil:
var cgI: CGImage?
VTCreateCGImageFromCVPixelBuffer(pixelBuffer!, options: nil, imageOut: &cgI)
How did you solve it?
Thank you for explaining the syntax. Excellent!
Good point about CGImageSourceOption. According to the CIFilter initializer - https://developer.apple.com/documentation/coreimage/cifilter/1437879-init#discussion, it is recommended to provide this option.
I will test this later today.
Hi ... I know it's been a while since this was posted.
I actually have the same question. Did you figure it out? And would you mind sharing?
Thanks!
... I know this is an old thread, but it looks like what I am trying to figure out. Maybe you could help me out ...
I have raw pixel data from a binary file and try to convert them into a CIImage. I decided to go via CVPixelBuffer in order to be able to provide the pixel layout (CFA) of my image sensor, which is a Sony RGGB (aka. "rgg4"). The rawImgData are [UInt16] with width*height number of elements, because I had to do some numerical treatment on the data.
This is how far I got so far. I am stuck with the pixel-buffer properties.
What do I have to put in the dictionary for CIFilter to create a raw image? I always get an error messages at line 10. The compiler does not like the "nil".
var pixelBuffer: CVPixelBuffer?
let attrs: [ CFString : Any ] = [ kCVPixelBufferCGImageCompatibilityKey : kCFBooleanTrue as Any,
kCVPixelBufferCGBitmapContextCompatibilityKey : kCFBooleanTrue as Any ]
CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, kCVPixelFormatType_14Bayer_RGGB, &imgRawData, 2*width, nil, nil, attrs as CFDictionary, &pixelBuffer)
let sourceTypeIdentifierHint = CIRAWFilterOption(rawValue: kCGImageSourceTypeIdentifierHint as String)
let rfo: [CIRAWFilterOption: Any] = [ sourceTypeIdentifierHint : "com.sony.raw-image" ]
let ciiraw = CIFilter(cvPixelBuffer: pixelBuffer, properties: nil, options: rfo).outputImage
I put this in this thread, because one could imagine to convert the pixel buffer into data object and then omit the properties in CIFilter. But maybe, I would loose too much info from the pixel buffer. No clue.
Thank you for your help!
I am stuck with a related issue. I have raw pixel data from a Sony chip in RGGB pixel arrangement. How do I assign/apply raw filter options with CIFilter?
The Apple Developer Documentation says you have to provide an identifier hint in the options, but I have no clue how to do this... The only example I found is outdated and the syntax provided causes a type error.
Any help or hint is highly appreciated. Thank you!
This is what I do, but it does not work...
let rfo = [ String(kCGImageSourceTypeIdentifierHint) : "com.sony.raw-image" ] as! [CIRAWFilterOption:Any]
let cii = CIFilter(imageData: ddata , options: rfo).outputImage
Hi...
same problem here! Did you solve it? I used .fill with .border and the edges are not rounded, either:
RoundedRectangle(cornerRadius: 20.0, style: .circular )
.frame(width: 50.0 , height: 50.0 )
.border(Color.blue, width: 2 )
.foregroundColor(Color.orange.opacity(0.2))
Same problem with ...
Xcode 12.3 (12C33) on iMac 5k 2017 (Big Sur 11.1) and
iPad Pro 11", 1st Gen, wit iPadOS 14.3
Unpairing and unpluging and re-plugging/re-trusting the iPad to the iMac did not work. Xcode could not deploy app to the iPad.
Shutting down the iPad and restarting the iPad did the job immediately!