Is there an equivalent of MATLAB's find() in opencv or numpy?
조회 수: 15 (최근 30일)
이전 댓글 표시
for image processing, i.e to find first/last array of matching pixels.
댓글 수: 0
답변 (2개)
Jan
2017년 3월 7일
편집: Jan
2017년 3월 7일
This is obviously a question for a numpy and opencv forum. But let's see, what an internet search engine finds...
itemindex = numpy.where(array==item)
And perhaps you want Cmp or CmpS in OpenCV, see e.g. http://stackoverflow.com/questions/10597107/opencv-function-similar-to-matlabs-find
댓글 수: 0
Bill Tubbs
2020년 2월 1일
I wasn't sure about this but you are correct. They both return indexes. I'll share these examples in case they help someone.
>> x = [1 2 3; 2 3 4];
>> find(x==2)
ans =
2
3
>> x(find(x==2))
ans =
2
2
>> find(x==3)
ans =
4
5
Python:
>>> x = np.array([[1, 2, 3], [2, 3, 4]])
>>> np.where(x == 2)
(array([0, 1]), array([1, 0]))
>>> x[np.where(x == 2)]
array([2, 2])
>>> np.where(x == 3)
(array([0, 1]), array([2, 1]))
Interesting how different indexing is in the two languages!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!