def spEdges(self, Kx) : self.I2 = self.Ilast if self.Ilast.ndim == 3 : self.onGryscl() self.I2 = self.Ilast tempX = myFunc.conv2(self.I2, Kx) tempY = myFunc.conv2(self.I2, np.transpose(Kx)) temp = np.abs(tempX) + np.abs(tempY) # calculate the new image self.onPanel2(temp)
def spKer(self, kernel,offset = 0): self.I2 = self.Ilast kernel = np.float32(kernel) self.I2= np.float32(self.I2) if self.Ilast.ndim == 3 : temp = np.zeros(self.I2.shape, dtype = self.I2.dtype) temp[:,:,0] = myFunc.conv2(self.I2[:,:,0], kernel) temp[:,:,1] = myFunc.conv2(self.I2[:,:,1], kernel) temp[:,:,2] = myFunc.conv2(self.I2[:,:,2], kernel) else: temp = myFunc.conv2(self.I2, kernel) np.putmask(temp, temp > 255.0, 255.0) # overfloe check np.putmask(temp, temp < 0.0, 0.0) # check underflow self.onPanel2(np.uint8(temp))
def canny(im): #blurring the image # with median filter of 5*5 temp = myFunc.medFilterSimple(im, 2) # High pass derivative based filters # with sobel operator Kx = [[1, 0, -1], [2, 0, -2], [1, 0, -1]] Gx = myFunc.conv2(temp, Kx) Gy = myFunc.conv2(temp, np.transpose(Kx)) Grad = np.hypot(Gx, Gy) theta = np.arctan2(Gx, Gy) edge_map = non_maximal_edge_suppresion(Grad,theta) edge_map = np.logical_and(edge_map, Grad > 50) m, n = im.shape gnh = np.zeros_like(edge_map) gnl = np.zeros_like(edge_map) th, tl = 0.2 * np.max(Grad), 0.1 * np.max(Grad) for x in range(1,m-1): for y in range(1,n-1): if Grad[x][y]>=th: gnh[x][y]=edge_map[x][y] if Grad[x][y]>=tl: gnl[x][y]=edge_map[x][y] gnl = gnl-gnh def traverse(i, j): x = [-1, 0, 1, -1, 1, -1, 0, 1] y = [-1, -1, -1, 0, 0, 1, 1, 1] for k in range(8): if gnh[i+x[k]][j+y[k]]==0 and gnl[i+x[k]][j+y[k]]!=0: gnh[i+x[k]][j+y[k]]=1 traverse(i+x[k], j+y[k]) for i in range(1, m-1): for j in range(1, n-1): if gnh[i][j]: gnh[i][j]=1 traverse(i, j) return np.uint8(gnh) * 255