Ask Your Question
0

Computing radial average of the autocorrelation of a binary image

asked 2015-02-06 16:22:11 -0600

Ohm gravatar 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

im_normal = cv2.imread('example.jpg')
im_gray = cv2.imread('example.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
(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 -patches

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-02-07 09:04:00 -0600

theodore gravatar image

updated 2015-02-07 15:26:44 -0600

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);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-06 16:22:11 -0600

Seen: 1,606 times

Last updated: Feb 07 '15