如何在DigitalMicrograph中为3D图像栈批量应用Band Pass Filter
自动化处理Gatan 3D图像栈的Band Pass Filter脚本及步骤
准备工作
- 确保使用的Gatan DigitalMicrograph(DM)版本支持脚本运行(v3.x及以上版本均支持)
- 加载需要处理的3D图像栈,确认图像栈包含多帧2D图像
核心DM Script脚本
以下脚本会遍历图像栈的每一帧,自动应用Band Pass Filter,可根据需求修改参数:
// 自定义Band Pass Filter参数,按需修改 Number lowCutoff = 0.02; // 低截止频率(单位:1/像素) Number highCutoff = 0.2; // 高截止频率(单位:1/像素) Number filterOrder = 4; // 滤波器阶数 Boolean useGaussian = false; // true=高斯型滤波器,false=巴特沃斯滤波器 // 获取当前激活的图像栈 ImageDocument targetDoc = GetFrontImageDocument(); if (targetDoc.ImageCount() == 0) { OKDialog("请先打开目标3D图像栈!"); exit(); } // 遍历所有帧并应用滤镜 for (Number frameIdx = 0; frameIdx < targetDoc.ImageCount(); frameIdx++) { Image currentFrame = targetDoc.Image(frameIdx); // 应用Band Pass Filter Image filteredFrame = BandPassFilter(currentFrame, lowCutoff, highCutoff, filterOrder, useGaussian); // 替换原帧(若需保留原数据,见下方替代方案) targetDoc.ReplaceImage(frameIdx, filteredFrame); // 可选:实时刷新当前帧显示(大栈处理建议注释以提速) // currentFrame.ShowImage(); } // 可选:自动保存处理后的图像栈 // targetDoc.SaveAs("处理完成的图像栈.dm3"); OKDialog("全栈Band Pass Filter处理完成!");
脚本运行步骤
- 打开Gatan DM并加载目标3D图像栈
- 点击顶部菜单栏
Script > New Script,新建空白脚本窗口 - 将上述脚本粘贴到窗口中,调整参数(截止频率、滤波器类型等)
- 点击脚本窗口的绿色运行按钮,或按
Ctrl+R执行脚本
保留原数据的替代方案
若不想覆盖原始图像栈,可修改脚本创建新图像栈存储处理结果:
// 替换原循环部分的代码 ImageDocument newDoc = NewImageDocument(); for (Number frameIdx = 0; frameIdx < targetDoc.ImageCount(); frameIdx++) { Image currentFrame = targetDoc.Image(frameIdx); Image filteredFrame = BandPassFilter(currentFrame, lowCutoff, highCutoff, filterOrder, useGaussian); newDoc.AddImage(filteredFrame); } // 显示新图像栈 newDoc.ShowImage(); // 保存新图像栈 // newDoc.SaveAs("处理后的图像栈.dm3");
注意事项
- 截止频率单位为1/像素,需根据图像实际分辨率调整:例如0.02对应50像素的空间周期,0.2对应5像素的空间周期
- 大帧数图像栈处理时,建议注释掉实时刷新代码(
currentFrame.ShowImage();)以提升处理速度 - 若需批量处理多个图像栈,可扩展脚本添加文件遍历逻辑,结合
OpenImageDocument()函数实现批量加载与处理
内容的提问来源于stack exchange,提问作者yale chen
相关产品推荐
相关产品推荐

