iphone - UIImage - implementing an auto levels algorithm -


I want to implement an "auto level" option for a UIImage that I'm displaying in my iPhone app I am Before I try to apply myself, I was wondering if there are any image processing methods in the API, which should be used for histogram etc. I should be used. Or should I just capture the underlying CGI image and process it? (I'm new to iPhone Dev.)

Thanks

MV

A very easy way to use the CGImage RF decoded array, but it can not help only for a border mapping (no gamma, etc.)

  const CGFloat decode [6] = {Black Point, Whitepoint, Black Point, Whitepoint, Black Point, White Point}; decodedImage = CGImageCreate (CGImageGetWidth (origImage), CGImageGetHeight (origImage), CGImageGetBitsPerComponent (origImage), CGImageGetBitsPerPixel (origImage), CGImageGetBytesPerRow (origImage), CGImageGetColorSpace (origImage), CGImageGetBitmapInfo (origImage), CGImageGetDataProvider (origImage), decode, yes, CGImageGetRenderingIntent ( Origin));  

While the white point is a float between 0.0 and 1.0, it determines how the pure white in the output will be mapped, and the blackpoint is also a float, determines that Black is mapped to purify the brightness.

The elements of the decode array correspond to the components of the colors, so this code will only work for RBG pictures. You can set the components to different white and black values ​​to create a simple color correction.

You can calculate white points and blackpoint with the following function (w / o color correction):

  Count zero Hypertexture value (CGMJ graphs, CGFlots * WhitePoint , CGFLOT * Black Point) {UInt8 * imageData = malloc (100 * 100 * 4); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB (); CGContextRef ctx = CGBitmapContextCreate (ImageData, 100, 100, 8, 4 * 100, ColorSpace, KCGImage alpha nonskip list); CGColorSpaceRelease (colorspace); CGContextDrawImage (ctx, CGRectMake (0, 0, 100, 100), image); Int histogram [256]; Berjo (histogram, 256 * size (int)); (Int i = 0; I & lt; 100 * 100 * 4; i + = 4) {UInt8 value = (image data [i] + image data [i + 1] + image data [i + 2]) / 3; Histogram [value] ++; } CGContextRelease (ctx); Free (imageData); Int black = 0; Int counter = 0; // (Black; Lieutenant; 200) & amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp;; Counter + = histogram [black]; To find the black point, calculate up to 200 (2%) values ​​from the black side of the histogram. ; Black ++; } Int white = 255; Counter = 0; // To find white point up to 200 (2%) value from the white side of the histogram (counter (<200) & amp; amp; amp ;; (white & gt; 0)) {counter + = Histogram [white]; White --; } * Black Point = 0.0 - (Black / 256.0); * White point = 1.0 + ((255-white) / 256.0); }  

Comments