Search code examples
ioscore-graphicsquartz-graphicsquartz-2dcgimage

Binary quantize a CGImage (is image majorly bright or dark)


I have a CGImage and I want to determine whether it is majorly bright or majorly dark. I can surely just iterate through the matrix and see whether a sufficient number of pixels exceed the desired threshold. However, since I am new to image processing, I assume there must be built-in functions in CoreGraphics or Quartz that are better suited, and maybe even accelerated.


Solution

  • CoreGraphics (aka Quartz 2D) doesn't have any functions for this. CoreImage on Mac OS X has CIAreaAverage and CIAreaHistogram, which might help you, but I don't think iOS (as of 5.0.1) has those filters.

    iOS does have the Accelerate framework. The vImageHistogramCalculation_ARGBFFFF function and related functions might help you.