astroML Python 모듈 에서 2 점 상관 함수를 수행해야합니다. 데이터는 원래 jpg 이미지, 흑백이며 OpenCV 이미지 임계 값을 사용하여 이진 이미지로 변환합니다 (올바르게 수행했는지 확실하지 않음). 문제는 2D 이진 행렬 또는 1과 0을 1의 좌표 목록으로 변환하는 방법입니다. 기본 코드 라인은 다음과 같습니다.
import numpy as np
import cv2
from astroML.correlation import two_point
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)
행렬의 모든 셀을 반복하고 좌표를 가져와야합니까 아니면 쉽게 할 수있는 방법이 있습니까?
분석을 수행하고 싶은 이미지-
네, 배열을 반복하여 수행하려고 생각했던 대부분의 작업과 마찬가지로 numpy에는 기본 제공 솔루션이 있습니다.
[numpy.nonzero][1]
numpy.nonzero(a)
Return the indices of the elements that are non-zero.
Returns a tuple of arrays, one for each dimension of a, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values can be obtained with:
`a[nonzero(a)]`
To group the indices by element, rather than dimension, use:
`transpose(nonzero(a))`
The result of this is always a 2-D array, with a row for each non-zero element.
코드 예 :
>>> x = np.eye(3)
>>> x
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> np.nonzero(x)
(array([0, 1, 2]), array([0, 1, 2]))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다