In [1]:
Copied!
from src.radon_analyser import RadonAnalyzer
import mrcfile
import numpy as np
import matplotlib.pyplot as plt
from src.radon_analyser import RadonAnalyzer
import mrcfile
import numpy as np
import matplotlib.pyplot as plt
Set the paramters¶
In [2]:
Copied!
templates_selected_mrcfile = './db/templates_selected.mrc'
section = 2
crop_rate = 0.7
threshold = 0.6
theta_start = 0
theta_end = 180
templates_selected_mrcfile = './db/templates_selected.mrc'
section = 2
crop_rate = 0.7
threshold = 0.6
theta_start = 0
theta_end = 180
Show the 2D average to be processed¶
In [3]:
Copied!
with mrcfile.open(templates_selected_mrcfile) as mrc:
average2D = mrc.data[section]
plt.imshow(average2D, cmap='gray', origin='lower')
with mrcfile.open(templates_selected_mrcfile) as mrc:
average2D = mrc.data[section]
plt.imshow(average2D, cmap='gray', origin='lower')
Out[3]:
<matplotlib.image.AxesImage at 0x127dde9a0>
Radon Analysis¶
In [4]:
Copied!
analyzer = RadonAnalyzer(average2D, crop_rate = crop_rate, thr = threshold, theta_start = theta_start, theta_end = theta_end)
analyzer.visualize_analyze()
rlnAngleTheta, rlnMembraneDistance = analyzer.return_results()
analyzer = RadonAnalyzer(average2D, crop_rate = crop_rate, thr = threshold, theta_start = theta_start, theta_end = theta_end)
analyzer.visualize_analyze()
rlnAngleTheta, rlnMembraneDistance = analyzer.return_results()
peaks: (array([53, 65]), array([24, 24])) point1: 53, 24; point2: 65, 24 average_theta: 24.0 membrane_distance: 12.0 b: 0.40673664307580015
====Radon Analysis Results==== average_theta: 24.0 membrane_distance: 12.0
In [5]:
Copied!
from src.template_centerfitting import *
from src.generate_gaussian_template import *
from src.calculate_curve import *
from src.generate_membrane_mask import *
from src.mem_average import *
from src.template_centerfitting import *
from src.generate_gaussian_template import *
from src.calculate_curve import *
from src.generate_membrane_mask import *
from src.mem_average import *
Set the paramters¶
In [6]:
Copied!
# Fit membrane center
template_size = 32
theta = rlnAngleTheta
membrane_distance = rlnMembraneDistance
initial_sigma1 = 3
initial_sigma2 = 3
sigma_range = 3
sigma_step = 0.5
# Curve fitting
kappa_start = -0.01
kappa_end = 0.01
kappa_step = 0.001
# Generate membrane mask
edge_sigma_mask = 3
# Generate Membrane Average
extra_mem_dist = 15
edge_sigma = 5
# Fit membrane center
template_size = 32
theta = rlnAngleTheta
membrane_distance = rlnMembraneDistance
initial_sigma1 = 3
initial_sigma2 = 3
sigma_range = 3
sigma_step = 0.5
# Curve fitting
kappa_start = -0.01
kappa_end = 0.01
kappa_step = 0.001
# Generate membrane mask
edge_sigma_mask = 3
# Generate Membrane Average
extra_mem_dist = 15
edge_sigma = 5
Generate the membrane template and search for the center¶
In [7]:
Copied!
template_center_fitter = Template_centerfitting(sigma1 = initial_sigma1, sigma2 = initial_sigma2, image = average2D, crop_rate = crop_rate, thr = threshold, theta_start = theta_start, theta_end = theta_end, template_size = template_size, sigma_range = sigma_range, sigma_step = sigma_step)
rlnCenterX, rlnCenterY = template_center_fitter.centerfinder()
template_center_fitter.visualize_center()
template_center_fitter = Template_centerfitting(sigma1 = initial_sigma1, sigma2 = initial_sigma2, image = average2D, crop_rate = crop_rate, thr = threshold, theta_start = theta_start, theta_end = theta_end, template_size = template_size, sigma_range = sigma_range, sigma_step = sigma_step)
rlnCenterX, rlnCenterY = template_center_fitter.centerfinder()
template_center_fitter.visualize_center()
====Center fitting results==== membrane center y: 61.7459764590515 membrane center x: 69.06261976221613
Search for the best sigma values¶
In [8]:
Copied!
rlnSigma1, rlnSigma2 = template_center_fitter.fit_sigma()
template_center_fitter.fit_sigma_visualize()
rlnSigma1, rlnSigma2 = template_center_fitter.fit_sigma()
template_center_fitter.fit_sigma_visualize()
====Sigma fitting results==== best sigma1: 3.2411764705882358 best sigma2: 4.811764705882353
Generate simulated membrane¶
In [9]:
Copied!
test_kappa = 0.005
curve_fitting = Curvefitting(image=average2D, kappa_start=kappa_start, kappa_end=kappa_end, kappa_step=kappa_step,
rlnCenterX=rlnCenterX, rlnCenterY=rlnCenterY, rlnAngleTheta=rlnAngleTheta,
rlnMembraneDistance=rlnMembraneDistance, rlnSigma1=rlnSigma1, rlnSigma2=rlnSigma2)
simulated_membrane_example = curve_fitting.generate_membrane(test_kappa)
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(average2D, cmap='gray', origin='lower')
axes[0].set_title('Original Image')
axes[1].imshow(simulated_membrane_example, cmap='gray', origin='lower')
axes[1].set_title(f'Simulated Membrane(kappa={test_kappa})')
test_kappa = 0.005
curve_fitting = Curvefitting(image=average2D, kappa_start=kappa_start, kappa_end=kappa_end, kappa_step=kappa_step,
rlnCenterX=rlnCenterX, rlnCenterY=rlnCenterY, rlnAngleTheta=rlnAngleTheta,
rlnMembraneDistance=rlnMembraneDistance, rlnSigma1=rlnSigma1, rlnSigma2=rlnSigma2)
simulated_membrane_example = curve_fitting.generate_membrane(test_kappa)
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(average2D, cmap='gray', origin='lower')
axes[0].set_title('Original Image')
axes[1].imshow(simulated_membrane_example, cmap='gray', origin='lower')
axes[1].set_title(f'Simulated Membrane(kappa={test_kappa})')
Out[9]:
Text(0.5, 1.0, 'Simulated Membrane(kappa=0.005)')