# Computing radial average of the autocorrelation of a binary image

Hello, I am a new user of OpenCV. I need to extract the typical distance between patches in a set of images I have. As I understand the right way to do it is performing the radial average of the autocorrelation of the image.

Is there a smart way to do it on OpenCV? I tried to search on this topic but haven't found something useful..

My data is originally a jpg image, black and white, and I convert it to binary image using OpenCV image thresholding(not sure that I did it right). The question is how now I convert the 2D binary matrix or ones and zeros to a list of the coordinates of only the ones. The basic code line is this one:

import numpy as np
import cv2
import matplotlib.pyplot as plt

(thresh, im_bw) = cv2.threshold(im_gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)


As an example for an image I attach here this one -

edit retag close merge delete

Sort by » oldest newest most voted

if you just want to extract the pixel coordinates of the non-zero pixels, then you can use the findNonZero() (for some reason I cannot find it in the documentation) function:

cv::Mat binaryImage; // input, binary image
cv::Mat locations;   // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);


and then access the coordinates by:

Point coordinate = locations.at<Point>(i);


Otherwise, you will have to do it by yourself through looping the binary image and pushing the x, y point values of the non-zero pixels into a vector<point> structure. You can find many examples how to do that if you search into the web.

edit ------------------------------------------------------------------------------------------------

it seems that passing coordinates straight forward to a vector<point> structure is also supported from the findNonZero() function, so you can just use:

cv::Mat binaryImage; // input, binary image
vector<Point> locations;   // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);

more

Official site

GitHub

Wiki

Documentation