def rotaxis_rough(proj, N_steps=10): """calculate the rotation axis comparing 0 and 180 projection shift Parameters __________ proj: 3D array N_steps: projections per degree by default it compares the central part of images (between 1/4 and 3/4 of shape) """ a = proj.shape[1] // 4 b = 3 * proj.shape[1] // 4 c = proj.shape[2] // 4 d = 3 * proj.shape[2] // 4 cent = [] N_rot = proj.shape[0] - 180 * N_steps for i in range(N_rot): distances = shift(proj[i, a:b, c:d], np.flip(proj[i + N_steps * 180, a:b, c:d], 1)) cent.append(proj[i].shape[1] / 2 + distances[1] / 2) return cent
def rotaxis_rough_filt(proj, N_steps=10, sigma=5, accuracy=10): """calculate the rotation axis comparing 0 and 180 projection shift Parameters __________ proj: 3D array N_steps: projections per degree by default it compares the central part of images (between 1/4 and 3/4 of shape) """ a = proj.shape[1] // 4 b = 3 * proj.shape[1] // 4 c = proj.shape[2] // 4 d = 3 * proj.shape[2] // 4 cent = [] N_rot = proj.shape[0] - 180 * N_steps for i in range(N_rot): im1 = filt_gauss_laplace(proj[i, a:b, c:d], sigma) im2 = np.flip( filt_gauss_laplace(proj[i + N_steps * 180, a:b, c:d], sigma), 1) distances = shift(im1, im2, accuracy) cent.append(proj[i].shape[1] / 2 + distances[1] / 2) return cent
def axis_raws(image1, image2, Npad=0, RotROI=None, level=5, window=50): """Finds an axis of rotation by comparing the 1st and the 180deg image: This function is based on rotaxis_rough() It is useful when you want to search for rotaxis in different regions of your image independently Parameters __________ image1: 2D array first 2D image image2: 2D array second 2D image Npad: int type the number here if the x axis of your image was padded RotROI: tuple ROI where to compare the images. Note that it is better to exclude some regions at the edge of the camera Coordinate legend: RotROI[0] - begin line (if you look at the image, numpy logic) RotROI[1] - end line RotROI[2] - begin column RotROI[3] - end column level: int the number of pixels to be taken into account, please type None if you don't want to use it and want to export the whole data. window: int window is the number of pixels on the image (height) to be taken into account during comaprison """ if not RotROI: RotROI = (50, image1.shape[0], Npad + image1.shape[1] // 8, image1.shape[1] - Npad - image1.shape[1] // 8) all_cent = [] for i in range(RotROI[0], RotROI[1], window // 2): im_1 = image1[i:i + window, RotROI[2]:RotROI[3]] im_2 = np.flip(image2[i:i + window, RotROI[2]:RotROI[3]], 1) distances = shift(im_1, im_2) cent = im_1.shape[1] / 2 + distances[1] / 2 + RotROI[2] all_cent.append(cent) #print('center for the slice #',i,' is: ', cent) if level: x = [] y = [] for i in range(len(all_cent)): if np.absolute(all_cent[i] - np.median(all_cent)) < level: x.append(i * window // 2) y.append(all_cent[i]) all_cent = np.column_stack((x, y)) else: all_cent = np.column_stack((np.linspace(0, len(all_cent), len(all_cent), dtype='uint16'), all_cent)) #plt.plot(all_cent[:,0], all_cent[:,1], 'bo') return all_cent