I doesn't know anything about pyhton. But I want to implement " Joachim Weickert 'Coherence-Enhancing Shock Filters' " for C++ and openCV. Only source code that I found written in pyhton.
opencv functions are OK . I can adapt but some variable structure which pyhton uses, I can't convert them.
Orginal code
https://github.com/opencv/opencv/blob/3.2.0/samples/python/coherence.py, and I need only this part.
<pre lang="Python"><pre>def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
h, w = img.shape[:2]
for i in xrange(iter_n):
print(i)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
eigen = cv2.cornerEigenValsAndVecs(gray, str_sigma, 3)
eigen = eigen.reshape(h, w, 3, 2) # [[e1, e2], v1, v2]
x, y = eigen[:,:,1,0], eigen[:,:,1,1]
gxx = cv2.Sobel(gray, cv2.CV_32F, 2, 0, ksize=sigma)
gxy = cv2.Sobel(gray, cv2.CV_32F, 1, 1, ksize=sigma)
gyy = cv2.Sobel(gray, cv2.CV_32F, 0, 2, ksize=sigma)
gvv = x*x*gxx + 2*x*y*gxy + y*y*gyy
m = gvv < 0
ero = cv2.erode(img, None)
dil = cv2.dilate(img, None)
img1 = ero
img1[m] = dil[m]
img = np.uint8(img*(1.0 - blend) + img1*blend)
print('done')
return img
Especially I don't understand this part :
<pre lang="Python">eigen = eigen.reshape(h, w, 3, 2) # [[e1, e2], v1, v2]
x, y = eigen[:,:,1,0], eigen[:,:,1,1]
and
m = gvv < 0 and after this it uses m for img1 array. img1[m] = dil[m]
Anybody can help about this?
What I have tried:
I can convert opencv functions but I stucked at arrays.