Good way to calculate 'brightness' of UIImage?

前端 未结 1 1354
青春惊慌失措
青春惊慌失措 2021-01-03 16:07

I\'m writing an app that will offer OCR of an image captured by the iPhone camera. I want to test the image before I perform the OCR analysis to see if there is sufficient l

相关标签:
1条回答
  • 2021-01-03 17:03

    The most flexible way is to generate a histogram for the red green and blue color channels, and then use it to determine the average lightness, median lightness, black/white points, contrast or other custom functions.

    Use CGBitmapContextCreate to create a bitmap context backed by a buffer of your creation, draw your image into it, then loop through each pixel in the buffer to populate the histograms.

    0 讨论(0)
提交回复
热议问题