Fast averaging function for images

3 replies [Last post]
shadowstriker
User offline. Last seen 9 years 2 weeks ago. Offline
Joined: 05/11/2012
Posts:

Hi Brad, thanks for the awesome work you put into GPUImage! Is there a fast way for calculating the average raw pixel values for an image (say 640x480)? Thanks for your input!

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 22 weeks ago. Offline
Joined: 05/14/2008
Posts:

Not yet. I need to do this as a filter that samples and generates progressively smaller images from the source. Using hardware texture filtering, each step would reduce the image by one fourth in each direction until you arrive at a 1x1 image containing the average image color (potentially adjusted based on mismatches between width and height dimensions).

Apple uses this process in their mean color Core Image filter, and describes it here: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch26.html

I just need to implement something that handles this operation.

shadowstriker
User offline. Last seen 9 years 2 weeks ago. Offline
Joined: 05/11/2012
Posts:

ah, thanks. i'd like to obtain the average as a floating point so being able to sum all the raw pixel values is important as opposed to getting the result as a 1x1 image.

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 22 weeks ago. Offline
Joined: 05/14/2008
Posts:

Unfortunately, you can't write to floating point textures on iOS, so the only way to extract a value other than 0-255 is to encode it as a color. Your best bet probably would be to extract that from a 1x1 RGBA image.

Syndicate content