How to detect an 'image area' percentage inside an image?

Posted by DaNieL on Stack Overflow See other posts from Stack Overflow or by DaNieL
Published on 2010-03-11T21:41:30Z Indexed on 2010/03/11 21:44 UTC
Read the original article Hit count: 289

Mhh, kinda hard to explain with my poor english ;)

So, lets say I have an image, doesnt matter what kind of (gif, jpg, png) with 200x200 pixel size (total area 40000 pixels)

This image have a background, that can be trasparent, or every color (but i know the background-color in advance).

Lets say that in the middle of this image, there is a picture (for keep the example simple lets suppose is a square drawn), of 100x100 pixels (total area 10000 pixels).

I need to know the area percentage that the small square fill inside the image.

So, in i know the full image size and the background-color, there is a way in php/python to scan the image and retrieve that (in short, counting the pixel that are different from the given background)?

In the above example, the result should be 25%

© Stack Overflow or respective owner

Related posts about php

Related posts about python