原始 MediaWiki 页面

我知道编辑这个网站吗?

使用 Jython 脚本分析 FRAP 电影

自迁移出 MediaWiki 以来,本页内容尚未经过审查。如果您愿意帮忙,请查看帮助指南

这是一个Jython脚本,用于分析FRAP电影。它是在Image Processing School Pilsen 2009期间开发的,并更新到现代斐济。

一旦加载了用户好的 FRAP 影片,well aligned with no drift,并指定了 FRAP 区域的 ROI 和另一个控制区域的 ROI,就可以自动分析 FRAP 曲线。这就是该脚本的目的:

  • 加载电影
  • 为 FRAP 区域相关 ROI,将其存储为 ROI 管理器中的第一个 ROI(按 T 键)
  • 对 FRAP 区域外部的控制区域相同的执行操作

然后在§§§5§§中加载此脚本,LanguagePython,然后运行它。将会测量所有帧的 FRAP 强度,尝试找到 FRAP 帧(通过找到 FRAP ROI 强度最小的帧),并通过递增指数生成 FRAP 曲线。然后可以在日志窗口中读取参数,并相关 FRAP 曲线及其附件。注意:背景被认为是 FRAP 之后 FRAP 区域的强度。

该脚本仅使用 ImageJ 函数来完成所有操作,但可以调整以使用更精美的斐济包含的绘图库,例如 JFreeChart。

import java.awt.Color as Color
from ij import WindowManager as WindowManager
from ij.plugin.frame import RoiManager as RoiManager
from ij.process import ImageStatistics as ImageStatistics
from ij.measure import Measurements as Measurements
from ij import IJ as IJ
from ij.measure import CurveFitter as CurveFitter
from ij.gui import Plot as Plot
from ij.gui import PlotWindow as PlotWindow
import math

# Get ROIs
roi_manager = RoiManager.getInstance()
roi_list    = roi_manager.getRoisAsArray()

# We assume first one is FRAP roi, the 2nd one is normalizing roi.
roi_FRAP    = roi_list[0];
roi_norm    = roi_list[1];

# Specify up to what frame to fit and plot.
n_slices = 30

# Get current image plus and image processor
current_imp  = WindowManager.getCurrentImage()
stack        = current_imp.getImageStack()
calibration  = current_imp.getCalibration()

#############################################

# Collect intensity values

# Create empty lists of number
If = []  # Frap values
In = []  # Norm values

# Loop over each slice of the stack
for i in range(0, n_slices):
 
    # Get the current slice 
    ip = stack.getProcessor(i+1)
 
    # Put the ROI on it
    ip.setRoi(roi_FRAP)
 
    # Make a measurement in it
    stats = ImageStatistics.getStatistics(ip, Measurements.MEAN, calibration);
    mean  = stats.mean
 
    # Store the measurement in the list
    If.append( mean  )

    # Do the same for non-FRAPed area
    ip.setRoi(roi_norm)
    stats = ImageStatistics.getStatistics(ip, Measurements.MEAN, calibration);
    mean = stats.mean
    In.append( mean  )
 
# Gather image parameters
frame_interval = calibration.frameInterval
time_units = calibration.getTimeUnit()
IJ.log('For image ' + current_imp.getTitle() )
IJ.log('Time interval is ' + str(frame_interval) + ' ' + time_units)
 
# Find minimal intensity value in FRAP and bleach frame
min_intensity = min( If )
bleach_frame = If.index( min_intensity )
IJ.log('FRAP frame is ' + str(bleach_frame+1) + ' at t = ' + str(bleach_frame * frame_interval) + ' ' + time_units )
 
# Compute mean pre-bleach intensity
mean_If = 0.0
mean_In = 0.0
for i in range(bleach_frame):         # will loop until the bleach time
    mean_If = mean_If + If[i]
    mean_In = mean_In + In[i]
mean_If = mean_If / bleach_frame
mean_In = mean_In / bleach_frame
 
# Calculate normalized curve
normalized_curve = []
for i in range(n_slices):
    normalized_curve.append( (If[i] - min_intensity) / (mean_If - min_intensity)   *   mean_In / In[i] )
    
x = [i * frame_interval for i in range( n_slices ) ] 
y = normalized_curve

xtofit = [ i * frame_interval for i in range( n_slices - bleach_frame ) ]
ytofit = normalized_curve[ bleach_frame : n_slices ]
 
# Fitter
fitter = CurveFitter(xtofit, ytofit)
fitter.doFit(CurveFitter.EXP_RECOVERY_NOOFFSET)
IJ.log("Fit FRAP curve by " + fitter.getFormula() )
param_values = fitter.getParams()
IJ.log( fitter.getResultString() )
 
# Overlay fit curve, with oversampling (for plot)
xfit = [ (t / 10.0  + bleach_frame) * frame_interval for t in range(10 * len(xtofit) ) ]
yfit = []
for xt in xfit:
    yfit.append( fitter.f( fitter.getParams(), xt - xfit[0]) )

 
plot = Plot("Normalized FRAP curve for " + current_imp.getTitle(), "Time ("+time_units+')', "NU", [], [])
plot.setLimits(0, max(x), 0, 1.2 );
plot.setLineWidth(2)


plot.setColor(Color.BLACK)
plot.addPoints(x, y, Plot.LINE)
plot.addPoints(x,y,PlotWindow.X);

 
plot.setColor(Color.RED)
plot.addPoints(xfit, yfit, Plot.LINE)

plot.setColor(Color.black);
plot_window =  plot.show()


# Output FRAP parameters
thalf = math.log(2) / param_values[1]
mobile_fraction = param_values[0]

str1 = ('Half-recovery time = %.2f ' + time_units) % thalf
IJ.log( str1 )
str2 = "Mobile fraction = %.1f %%" % (100 * mobile_fraction)
IJ.log( str2 )