Python: using function on 2 elements of different 2d numpy arrays -
i want sum of equivalent indexes of 2 arrays , threshold them. code runs slow , have use function often. there more efficient way in python?
sobelx = cv2.sobel(smoothed,cv2.cv_64f,1,0,ksize=-1) sobely = cv2.sobel(smoothed,cv2.cv_64f,0,1,ksize=-1) in range(0,height-1): j in range(0,width-1): xvalue= sobelx[i,j] yvalue= sobely[i,j] tmp = math.sqrt(math.pow(xvalue,2) + math.pow(yvalue,2)) if tmp > 255: tmp = 255 elif tmp <0: tmp =0 self.gradientmap[i,j] = tmp
this should trick:
sobelx = cv2.sobel(smoothed,cv2.cv_64f,1,0,ksize=-1) sobely = cv2.sobel(smoothed,cv2.cv_64f,0,1,ksize=-1) self.gradientmap = numpy.sqrt (sobelx ** 2 + sobely ** 2) self.gradientmap[self.gradientmap> 255] = 255
i don't know exact type of sobelx
, sobely
assumed there 2 numpy.array
questions.
note: removed tmp < 0
case because never have negative square root.
Comments
Post a Comment