def calculate_one_image_sectioned_fsc(image, args, z_correction=1): """ A function to calculate one-image sectioned FSC. I assume here that prior to calling the function, the image is going to be in a correct shape, resampled to isotropic spacing and zero padded. If the image dimensions are wrong (not a cube) the function will return an error. :param image: a 3D image, with isotropic spacing and cubic shape :type image: Image :param options: options for the FSC calculation :type options: argparse options :param z_correction: correction, for anisotropic sampling. It is the ratio of axial vs. lateral spacing, defaults to 1 :type z_correction: float, optional :return: the resolution measurement results organized by rotation angle :rtype: FourierCorrelationDataCollection object """ assert isinstance(image, Image) assert all(s == image.shape[0] for s in image.shape) image1, image2 = imops.checkerboard_split(image) image1 = Image(windowing.apply_hamming_window(image1), image1.spacing) image2 = Image(windowing.apply_hamming_window(image2), image2.spacing) iterator = iterators.AxialExcludeHollowConicalFourierShellIterator( image1.shape, args.d_bin, args.d_angle, args.d_extract_angle) fsc_task = DirectionalFSC(image1, image2, iterator) data = fsc_task.execute() analyzer = fsc_analysis.FourierCorrelationAnalysis(data, image1.spacing[0], args) result = analyzer.execute(z_correction=z_correction) def func(x, a, b, c, d): return a * np.exp(c * (x - b)) + d params = [0.95988146, 0.97979108, 13.90441896, 0.55146136] for angle, dataset in result: point = dataset.resolution["resolution-point"][1] cut_off_correction = func(point, *params) dataset.resolution["spacing"] /= cut_off_correction dataset.resolution["resolution"] /= cut_off_correction return result
def calculate_single_image_frc(image, args, average=True, trim=True, z_correction=1): """ A simple utility to calculate a regular FRC with a single image input :param image: the image as an Image object :param args: the parameters for the FRC calculation. See *miplib.ui.frc_options* for details :return: returns the FRC result as a FourierCorrelationData object """ assert isinstance(image, Image) frc_data = FourierCorrelationDataCollection() # Hamming Windowing if not args.disable_hamming: spacing = image.spacing image = Image(windowing.apply_hamming_window(image), spacing) # Split and make sure that the images are the same siz image1, image2 = imops.checkerboard_split(image) #image1, image2 = imops.reverse_checkerboard_split(image) image1, image2 = imops.zero_pad_to_matching_shape(image1, image2) # Run FRC iterator = iterators.FourierRingIterator(image1.shape, args.d_bin) frc_task = FRC(image1, image2, iterator) frc_data[0] = frc_task.execute() if average: # Split and make sure that the images are the same size image1, image2 = imops.reverse_checkerboard_split(image) image1, image2 = imops.zero_pad_to_matching_shape(image1, image2) iterator = iterators.FourierRingIterator(image1.shape, args.d_bin) frc_task = FRC(image1, image2, iterator) frc_data[0].correlation["correlation"] *= 0.5 frc_data[0].correlation["correlation"] += 0.5 * frc_task.execute( ).correlation["correlation"] freqs = frc_data[0].correlation["frequency"].copy() def func(x, a, b, c, d): return a * np.exp(c * (x - b)) + d params = [0.95988146, 0.97979108, 13.90441896, 0.55146136] # Analyze results analyzer = fsc_analysis.FourierCorrelationAnalysis(frc_data, image1.spacing[0], args) result = analyzer.execute(z_correction=z_correction)[0] point = result.resolution["resolution-point"][1] log_correction = func(point, *params) result.resolution["spacing"] /= log_correction result.resolution["resolution"] /= log_correction return result
def calculate_single_image_sectioned_frc(image, args, rotation=45, orthogonal=True, trim=True): """ A function utility to calculate a single image FRC on a Fourier ring section. The section is defined by the section size d_angle (in args) and the section rotation. :param image: the image as an Image object :param args: the parameters for the FRC calculation. See *miplib.ui.frc_options* for details :param rotation: defines the orientation of the fourier ring section :param orthogonal: if True, FRC is calculated from two sections, oriented at rotation and rotation + 90 degrees :return: returns the FRC result as a FourierCorrelationData object """ assert isinstance(image, Image) frc_data = FourierCorrelationDataCollection() # Hamming Windowing if not args.disable_hamming: spacing = image.spacing image = Image(windowing.apply_hamming_window(image), spacing) # Run FRC def frc_helper(image1, image2, args, rotation): iterator = iterators.SectionedFourierRingIterator( image1.shape, args.d_bin, args.d_angle) iterator.angle = rotation frc_task = FRC(image1, image2, iterator) return frc_task.execute() image1, image2 = imops.checkerboard_split(image) image1, image2 = imops.zero_pad_to_matching_shape(image1, image2) image1_r, image2_r = imops.reverse_checkerboard_split(image) image1_r, image2_r = imops.zero_pad_to_matching_shape(image1_r, image2_r) pair_1 = frc_helper(image1, image2, args, rotation) pair_2 = frc_helper(image1_r, image2_r, args, rotation) pair_1.correlation["correlation"] * 0.5 pair_1.correlation[ "correlation"] += 0.5 * pair_2.correlation["correlation"] if orthogonal: pair_1_o = frc_helper(image1, image2, args, rotation + 90) pair_2_o = frc_helper(image1_r, image2_r, args, rotation + 90) pair_1_o.correlation["correlation"] * 0.5 pair_1_o.correlation[ "correlation"] += 0.5 * pair_2_o.correlation["correlation"] pair_1.correlation[ "correlation"] += 0.5 * pair_1_o.correlation["correlation"] frc_data[0] = pair_1 freqs = frc_data[0].correlation["frequency"].copy() def func(x, a, b, c, d): return a * np.exp(c * (x - b)) + d params = [0.95988146, 0.97979108, 13.90441896, 0.55146136] # Analyze results analyzer = fsc_analysis.FourierCorrelationAnalysis(frc_data, image1.spacing[0], args) result = analyzer.execute()[0] point = result.resolution["resolution-point"][1] log_correction = func(point, *params) result.resolution["spacing"] /= log_correction result.resolution["resolution"] /= log_correction return result