def _normalization(image): assert image.__class__ == numpy.ndarray row, col = image.shape #stdImag standardized image stdImg = numpy.zeros((row, col)) """ What image.sum() do is the same as the following code but more faster than this. for i in xrange(self.Row): for j in xrange(self.Col): sigma += image[i][j] """ #sigma = image.sum() meanVal = image.mean() stdValue = image.std() if stdValue == 0: stdValue = 1 stdImg = (image - meanVal) / stdValue return stdImg
def Normimg(image): row, col = image.shape img_new = np.zeros((row, col)) meanVal = image.mean() stdValue = image.std() if stdValue == 0: stdValue = 1 img_new = (image - meanVal) / stdValue return img_new
def _normalization(image): assert image.__class__ == numpy.ndarray row, col = image.shape stdImg = numpy.zeros((row, col)) meanVal = image.mean() stdValue = image.std() if stdValue == 0: stdValue = 1 stdImg = (image - meanVal)/stdValue return stdImg
def vertical_edge(width, height, matrix): sosm = 3 vef = np.array([[1, 0, -1], [1, 0, -1], [1, 0, -1]]) row = (height - sosm) + 1 column = (width - sosm) + 1 result = [] r = (height - sosm) + 1 c = (width - sosm) + 1 for i in range(row): for j in range(column): sq = matrix[i:i + sosm, j:j + sosm] sum = 0 for k in range(3): for l in range(3): sum += (sq[k, l] * vef[k, l]) result.append(sum) result_matrix = np.asarray(result).reshape(r, c) return result_matrix img = img.imread('rubiks-cube.jpg') black_n_white = img.mean(axis=2) #converting to grayscale image h, w = black_n_white.shape #shape of the matrix vertical = vertical_edge(w, h, black_n_white) horizontal = horizontal_edge(w, h, black_n_white) image = np.sqrt((vertical**2) + (horizontal**2)) #combining both plt.imshow(image, cmap='gray', interpolation='nearest') #collecting the final image plt.show()