def zernike(zernike_indexes, labels, indexes): """Compute the Zernike features for the labels with the label #s in indexes returns the score per labels and an array of one image per zernike feature """ # # "Reverse_indexes" is -1 if a label # is not to be processed. Otherwise # reverse_index[label] gives you the index into indexes of the label # and other similarly shaped vectors (like the results) # if indexes == None: indexes = np.arange(1, nindexes + 1, dtype=np.int32) else: indexes = np.array(indexes, dtype=np.int32) nindexes = len(indexes) reverse_indexes = -np.ones((np.max(indexes) + 1, ), int) reverse_indexes[indexes] = np.arange(indexes.shape[0], dtype=int) mask = reverse_indexes[labels] != -1 centers, radii = minimum_enclosing_circle(labels, indexes) y, x = np.mgrid[0:labels.shape[0], 0:labels.shape[1]] xm = x[mask].astype(float) ym = y[mask].astype(float) lm = labels[mask] # # The Zernikes are inscribed in circles with points labeled by # their fractional distance (-1 <= x,y <= 1) from the center. # So we transform x and y by subtracting the center and # dividing by the radius # ym = (ym - centers[reverse_indexes[lm], 0]) / radii[reverse_indexes[lm]] xm = (xm - centers[reverse_indexes[lm], 1]) / radii[reverse_indexes[lm]] # # Blow up ym and xm into new x and y vectors # x = np.zeros(x.shape) x[mask] = xm y = np.zeros(y.shape) y[mask] = ym # # Pass the resulting x and y through the rest of Zernikeland # score = np.zeros((nindexes, len(zernike_indexes))) for i in range(len(zernike_indexes)): zf = construct_zernike_polynomials(x, y, zernike_indexes[i:i + 1], mask) one_score = score_zernike(zf, radii, labels, indexes) score[:, i] = one_score[:, 0] return score
def zernike(zernike_indexes, labels, indexes): """Compute the Zernike features for the labels with the label #s in indexes returns the score per labels and an array of one image per zernike feature """ # # "Reverse_indexes" is -1 if a label # is not to be processed. Otherwise # reverse_index[label] gives you the index into indexes of the label # and other similarly shaped vectors (like the results) # if indexes == None: indexes = np.arange(1, nindexes + 1, dtype=np.int32) else: indexes = np.array(indexes, dtype=np.int32) nindexes = len(indexes) reverse_indexes = -np.ones((np.max(indexes) + 1,), int) reverse_indexes[indexes] = np.arange(indexes.shape[0], dtype=int) mask = reverse_indexes[labels] != -1 centers, radii = minimum_enclosing_circle(labels, indexes) y, x = np.mgrid[0 : labels.shape[0], 0 : labels.shape[1]] xm = x[mask].astype(float) ym = y[mask].astype(float) lm = labels[mask] # # The Zernikes are inscribed in circles with points labeled by # their fractional distance (-1 <= x,y <= 1) from the center. # So we transform x and y by subtracting the center and # dividing by the radius # ym = (ym - centers[reverse_indexes[lm], 0]) / radii[reverse_indexes[lm]] xm = (xm - centers[reverse_indexes[lm], 1]) / radii[reverse_indexes[lm]] # # Blow up ym and xm into new x and y vectors # x = np.zeros(x.shape) x[mask] = xm y = np.zeros(y.shape) y[mask] = ym # # Pass the resulting x and y through the rest of Zernikeland # score = np.zeros((nindexes, len(zernike_indexes))) for i in range(len(zernike_indexes)): zf = construct_zernike_polynomials(x, y, zernike_indexes[i : i + 1], mask) one_score = score_zernike(zf, radii, labels, indexes) score[:, i] = one_score[:, 0] return score