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 read_flat(j): """ j: int an index of the file that should be processed Please note, j always starts from zero To open correct file, images array uses images[i][j + N_start-1] """ #global ff_shared, ff_con, shifts, indexes, Pro #set local variables ff = tonumpyarray(ff_shared.shared_array_base, ff_shared.shape, ff_shared.dtype) proj_loc = tonumpyarray(proj.shared_array_base, proj.shape, proj.dtype) shift = tonumpyarray(shifts.shared_array_base, shifts.shape, shifts.dtype) #LoI = tonumpyarray(indexes.shared_array_base, indexes.shape, indexes.dtype) ROI_ff = Pro.ROI_ff ROI = Pro.ROI images = Pro.images N_start = Pro.N_start Npad = Pro.Npad #read image and do ff-retrieval filt = [] for i in np.arange(len(images)): im = tifffile.imread(images[i][j + N_start - 1])[ROI[1]:ROI[3], ROI[0]:ROI[2]] index = SSIM_sf.SSIM( SSIM_const(im[ROI_ff[1]:ROI_ff[3], ROI_ff[0]:ROI_ff[2]]), ff_con[i]).ssim() im = im / ff[i][np.argmax(index)] filt.append(im) #LoI[j,i] = np.argmax(index) #calculate shift for holograms im_gau0 = var.filt_gauss_laplace(filt[0][ROI_ff[1]:ROI_ff[3], ROI_ff[0]:ROI_ff[2]], sigma=5) for i in np.arange(len(filt)): im_gau1 = var.filt_gauss_laplace(filt[i][ROI_ff[1]:ROI_ff[3], ROI_ff[0]:ROI_ff[2]], sigma=5) shift[j, i] = (var.shift_distance(im_gau0, im_gau1, 10)) #shift images filt = multiCTF.shift_imageset(np.asarray(filt), shift[j]) filt = np.asarray(filt) #do CTF retrieval filt = np.pad(filt, ((0, 0), (Npad, Npad), (Npad, Npad)), 'edge') # padding with border values filt = multiCTF.multi_distance_CTF(filt, beta_delta, fresnelN, zero_compensation) filt = filt[Npad:(filt.shape[0] - Npad), :] # unpad images from the top #rotate the image to compensate for the inclined rotation axis #filt = rotate(filt, inclination, mode = 'nearest', axes = (1,0)) #save to memory proj_loc[j] = filt