Let say that we have a gray-scale image. Is there a way to calculate how the non-black pixels are distributed, i.e. whether they are grouped at one or several places or they are distributed uniformly in the whole image?
3 Answers
It sounds like you're looking for is the spacial moments of a rasterized version of your image.
First you need to threshold your image to make it binary: http://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html?highlight=threshold#threshold
You can then calculate the image moments: http://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments
If you'd like a physical analogy of the spacial moments you can imagine that each white pixels is a unit point mass, then the second moment would be the rotational inertia of the image. If the white pixels (point masses) are tightly clustered then the second moment will be low (image will rotate easily).

- 1
- 1
I want to share another approach that I have used.
Mat img = imread(argv[1], CV_LOAD_IMAGE_COLOR);
cvtColor(img, img, CV_RGB2GRAY);
threshold(img, img, 35, 255, THRESH_BINARY);
Mat distance;
distanceTransform(img, distance, CV_DIST_L2, 3);
distance = min(distance, 1);
Scalar distribution = mean(dist);
cout << "The distribution is: " << distribution << std::endl;
The tricky part is the combination of distanceTransform and min functions. The effect of the min function will be smaller on images with good distribution and the mean value will be greater.

- 1,698
- 4
- 21
- 32