A
A
Alexey Belov2019-10-11 17:04:29
Python
Alexey Belov, 2019-10-11 17:04:29

How to find a shape inside a 2D Numpy array while having an outline?

I have a shape contour - cnt, I need to find it inside a two-dimensional array, I have a target_index variable, it is used to find the required zone, but I need to find the cnt contour zone in it.

import numpy as np

x = np.linspace(0,1000, int(1000/50))
y = np.linspace(0,1000, int(1000/50))
X,Y = np.meshgrid(x,y)

source =  np.column_stack([X.ravel(), Y.ravel()]).astype(int)
destination = source.copy()

#cnt = 

# Need to use cnt here
target_index = np.where(np.logical_and(destination[:,1]==789,destination[:,0]>=421))

destination[target_index]
scope = destination[target_index] 
scope[:,0] = scope[:,0] + 10
destination[target_index] = scope
destination[target_index]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lz961, 2019-10-12
@lz961

A suitable solution is probably contained in the scikit-image library. In any case, the library solution will work faster than any implemented by means of the language itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question