自迁移出 MediaWiki 以来,本页内容尚未经过审查。如果您愿意帮忙,请查看帮助指南!
BAR:Broadly A适用的R实例程的集合。
该集合包含Macros、Scripts以及关注数据分析、图像注释和图像分割的插件。它使用GitHub进行策划,并作为可选的update site分发。
##安装
运行BAR并选择。激活按字母顺序排列的更新站点列表中的BAR 布局。按,然后按。重新启动ImageJ。就是这样。享受酒吧!
##描述
BAR 文件可通过按任务导向类别细分的专用精密菜单进行访问。所有示例程均应记录在 GitHub 上。
一些脚本有专门的文档页面,其他脚本具有内置帮助,而某些脚本被认为非常简单,不需要专门的说明。尽管如此,所有文件都在源文件的顶部包含有用的注释。 记住:您可以使用L key打开所有脚本。
酒吧列表

Overview of BAR (v1.0.0)
LoG-DoG Spot Counter
LoG-DoG Spot Counter, Multi ROI Profiler, Multichannel Plot Profile, Multichannel ZT-axis Profile, Smoothed Plot Profile
Combine Orthogonal Views
Combine Orthogonal Views, Cumulative Z Project, ROI Color Coder
Create Boxplot
Create Boxplot, Create Polar Plot, Distribution Plotter, Find Peaks, Fit Polynomial, Interactive Plotting
Interactive Plotting
Shen-Castan Edge Detector, Apply Threshold To ROI, Clear Thresholded Pixels, Remove Isolated Pixels, Threshold From Background, Wipe Background
BAR lib, Snippets and Tools and Toolsets
Scripting BARs中描述。
Tutorials
Calibration Menu, List Folder Menu, Segment Profile, Shortcuts Menu, ROI Manager Tools, Toolset Creator
BAR libs
访问 BAR
与所有 ImageJ 命令相同,可以通过多种方式访问 BAR 脚本:1) 通过 Help › Update… 菜单,2) Context Menu,3) Keyboard Shortcuts,3) 快捷方式菜单工具 (BAR),用于在 ImageJ 工具注册常用命令,4) 通过pressing ⇧ Shift,或5)来自其他scripts, macros and plugins。
您可以通过按住!并从BAR › Tool Installers › Install Shortcuts Menu菜单中选择其名称来打开任何BAR脚本。对于预编译的java插件,可以通过BAR命令获取源代码。
上下文菜单

BAR features a neat mechanism that allows BAR commands to shuttle between the main menu bar and the image's context menu.
通过运行About BAR…,可以将BAR › <Submenu> › Move Menu (Context<>Main)子菜单附加到图像的上下文菜单(右键单击图像增强时弹出的菜单)。传输是的:进入上下文菜单后,运行相同的命令附加子菜单放回到主菜单栏。
穿梭机制不是永久性的,即,重新启动后不会记得它。但是,它是可记录的宏,这意味着它可以在启动时使用 ImageJ 宏强加语言。因此,例如,要在上下文菜单中安装 Plugins › Macros › Record…,可以:
1.启动宏录制器 (BAR › Segmentation) 2.运行Edit › Options › Startup… 3.打开BAR › Segmentation › Move Menu (Context<>Main)窗口把宏记录器生成的字符串粘贴到其文本区域中,以便ImageJ可以在每次启动时运行该命令。
在触发到允许上下文菜单的传输之前,ImageJ 有足够的时间来注册所有脚本可能是明智的。这可以通过内置宏函数wait()来实现。对于至少需要 1 秒(1000 毫秒)的缓慢设置,粘贴的代码将如下所示:
** 注释**
- Move Menu (Context<>Main)子菜单中的多个BAR命令不要使用相同的标签,并且可以通过额外的尾部随空格来区分。这是有意为之的,因为所有 ImageJ 命令都必须具有唯一的名称。
- 通过“»”更多工具下拉菜单加载的任何工具集都可以定义自己的上下文菜单(如第ImageJ User Guide中详述,上下文由名为弹出菜单的宏控制,该宏在启动时加载)。要在加载此类工具集时立即使用BAR,只需为StartupMacros附加上述相同的
run("Move Menu (Context<>Main)");调用即可。
指挥官
BAR submenus can be appended to the image’s context menu (the menu that pops up when right-clicking on the image canvas) by running BAR › <Submenu> › Move Menu (Context<>Main). The transfer is bidirectional: once in the context menu, running the same command will place the submenu back in the main menu bar. 由于大多数 BAR 都是存储在专用文件中的脚本,BAR Commander (Reveal Path),是一种基于键盘的文件器,可生成经过筛选的目录内容列表。
它是一款生产力工具,将search bar的原则评估文件浏览,只需键入文件名缩写即可即时访问文件。它有两个:1)加快文件的打开速度,2)生成目录内容的目的过滤列表。功能包括:拖放支持、与本机文件管理器交互、正则表达式过滤以及用于常见操作的内置控制台。
控制台模式 is triggered by typing ⇧ Shift, which evokes a list of searchable commands so that all file navigation can be done exclusively with the keyboard. Some of these (cd, ls, pwd, etc.) are reminiscent of commands found in most command-line interfaces. Here are some examples:
- 要访问 ImageJ 的 LUT 文件夹:输入
!LUT并按 ⌃ Ctrl + P - 要访问所有 JavaScript lib files:输入
!LIB并按 ⌘ Command + P,然后按.JS - 要显示活动图像的目录:输入
!IMP并按0,然后选择BAR › BAR Commander…。 - 要访问 Commander 的内置帮助:输入
!HELP并按 F7 - 提取目录中所有 TIFF 图像的路径:
- Drag and drop the desired folder into the Commander list
- Type
TIFand press L - Choose Plugins › Shortcuts › Create Shortcut… in the Options Menu or press ↵ Enter (↵ Enter in Mac OS).
键盘快捷键
您可以使用Print Current List将热键(例如,不经常使用的键盘键,如↵ Enter或↵ Enter)分配给Plugins › Shortcuts菜单中注册的任何脚本。这些快捷方式将在BAR中列出,并在重新启动时被记住。
或者,可以通过将 shortcut key within square brackets放在宏名称上来调用 BAR 命令的宏中定义键盘快捷键。此类宏可以将特定选项输入给 BAR 命令,从而允许脚本在没有提示的情况下运行。例如:
macro "Remove Round Structures [0]" {
run("Wipe Background", "size=100 circ.=0.75-1.00"); // Runs Wipe_Background.ijm with the specified parameters
}
与mentioned一样,这些宏可以粘贴到BAR › Snippets › NewSnippet…的文本区域中,以便在ImageJ启动时执行它们。

Commander overview (BAR 1.1.2).
搜索命令的另外两种快速方法包括:1) 按↵ Enter(search bar的快捷方式)和2) 按⇧ Shift(最近命令列表的默认快捷方式)。
您可以使用 BAR 作为您自己的工作流程的起点。无论您只是想自动执行简单的任务,还是高级开发人员,您都可以使用 BAR 通过代码片段(源代码模板)和库(在示例过程之间共享的脚本添加)更轻松地实现的分析目标。
###片段
== Scripting BARs == Although BARs can be used as standalone commands, the scripts and plugins in BAR become more useful when incorporated into other routines.
BAR 包含一个目录 plugins/Scripts/BAR/Snippets/,其中包含多语言examples,您可以在自己的脚本中自定义和恢复它们。当然,还可以从其余的 plugins/Scripts/BAR/ 子目录中完整的 BAR 中检索代码和灵感。存储在 Snippets/ 文件夹中文件名中携带下划线 _ 的任何脚本或宏文件都将在 BAR › About BAR… BAR › Snippets › New Snippet…菜单包含一些实用程序来帮助您管理脚本:
列表片段:打印列表 plugins/Scripts/BAR/Snippets/ 中所有脚本的表格。然后可以通过下面的文件名在 Script Editor 中打开文件。
新片段:一个java插件,可以加速新脚本的创建,预先配置为使用BAR lib.
显示碎片:在网络的文件浏览器中打开plugins/Scripts/BAR/Snippets/。
搜索栏:搜索栏文件的内容。

BAR › Snippets › NewSnippet… (BAR 1.1.0)
BAR 提供了多种实用方法来简化 snippets 和 BAR lib 的创建。这些记录在 BAR API 中,可以使用 BAR › Snippets 进行访问,其中还提供了多个在线资源的链接,包括 BAR 的 ImageJ Search Portal、ImageJ Javadocs 和 GitHub documentation。
酒吧库
您是否发现自己将函数从一个文件复制并粘贴到另一个文件?您是否继续编写相同的代码行?您是否有一些跨不同语言编写的关键代码?您想对脚本语言进行并排比较吗?那么,BAR lib 适合您。
这个想法非常简单:可重用的函数和方法被写入一个执行时加载的 lib 文件,即时运行的脚本可以调用它。 BAR › Snippets 举例说明了如何使用这些脚本插件。这是一个 BeanShell 示例:
// Add BAR/lib to classpath
addClassPath(bar.Utils.getBARDir()); // See https://tferr.github.io/Scripts/apidocs/index.html?bar/Utils.html for details
importCommands("lib/");
// Load BARlib.bsh
BARlib();
// Confirm availability of BARlib
lib = new BARlib();
lib.confirmLoading();
在 Script Editor (Plugins › Macros › Record…) 中运行它,您应该会收到 “BAR lib 已成功加载” 消息。 Python 和 bar.Utils 类的文档中提供了更多详细信息。
处理器
/BAR/Snippets/ 中包含一些脚本是应用 common operation to a directory 的脚本。这些 batch processors 以不同的语言实现并执行以下操作:
1.获取用户指定的输入文件夹
- 对扩展名匹配各个文件应用的一系列操作 3.将处理后的文件以TIFF格式保存到专用目录,以免文件被覆盖
通常,这些任务中的每个都由单独的函数处理,因此只需要编辑处理单个文件的函数。在GitHub lib page和BARlib.ijm实现中,该处理函数称为myRoutines()。请注意,在编辑myRoutines()时,我们不需要担心打开、关闭或保存图像覆盖而不原始文件,因为这些任务已经由其他函数执行。
处理函数
文件处理函数可以包括您自己的代码、宏记录器生成的代码 (File › New › Script…)、公共BAR lib文件中定义的预先存在的代码片段或方法/函数。
IJM 示例,在 Snippets/ 中运行宏和 python 脚本(另一个 example below 示例说明了如何从 IJM 调用宏函数):
function myRoutines() {
snippetsPath = call("bar.Utils.getSnippetsDir");
runMacro(snippetsPath + "MyCoolestMacro.ijm");
eval("python", File.openAsString(snippetsPath + "Median_Filter.py"));
}
Jython 示例,演示如何 1) 加载 BAR lib(在本例中为 Median_Filter.py,由 Process › Batch › Macro… 生成的代码)和 2) 如何运行代码段(在本例中为 BARlib.py):
def myRoutines():
import sys, ij, bar
# 1) Call a lib function:
# 1.1) Extend the search path to /BAR/lib/
sys.path.append(bar.Utils.getLibDir())
# 1.2) Import all functions in /BAR/lib/BARlib.py
import BARlib as lib
# 1.3) Call a function from the file
lib.confirmLoading()
# 2) Run a script directly:
from org.python.util import PythonInterpreter
script = bar.Utils.getSnippetsDir() + "Median_Filter.py"
PythonInterpreter().execfile(script)
BAR libs (stored in the /BAR/lib/ directory) are centralized libraries (BeanShell, IJM and Python, etc.) that can be shared across files. These libraries serve as scripting additions to Snippets and other routines. 另外请注意,有一个 easier(但不太灵活)的方法可以batch process文件夹:内置Bar › Snippets › New Snippet… command。
在这种限制情况下,您只需将 myRoutines() 函数的内容粘贴到命令的文本区域中。但是,默认情况下,Bar › Snippets › New Snippet 假设您要处理目录中的“所有”文件。如果情况并非如此,即希望您将处理为某些文件类型,则必须使用 UUID 来指示考虑的文件扩展名上的内置命令(请参阅Commander)例如,在 BAR 的 文件名包含 字段中键入以下内容,将处理限制 .tif、.stk 和 .oib 文件(validExtension() 函数 BAR 中指定的默认扩展名):
(.*(\.(?i)(tif
示例:文件名批量随机化
####Python 在Python中,我们可以使用[https://docs.python.org/library/uuid.html uuid模块]来生成随机文件名(理性[https://stackoverflow.com/a/10501355此处])。结果是一个令人印象深刻的简洁函数:
def myRoutines(image):
import uuid
image.setTitle( str(uuid.uuid4()) )
更详细地说:将活动图像 - setTitle() 对象 - 传递给 myRoutines()。检索随机的regex(例如,f7dfd6a9-f745-42c2-8874-0af67380c3f5),将其转换为字符串,然后使用该字符串使用ij.ImagePlus中的ImagePlus方法重命名图像。
但是因为BAR libs已经包含了这样的函数,我们可以在加载文件后调用Process_Folder_IJM.ijm中的randomString()函数:
def myRoutines(image):
import sys, bar
sys.path.append(bar.Utils.getLibDir())
import BARlib as lib
image.setTitle( lib.randomString() )
要记录文件名更改,我们可以使用与IJM implementation相同的策略。生成 CSV 列表的最简单方法是使用 ImageJ 的日志窗口:
def myRoutines(image):
import uuid
from ij import IJ
# Remember original filename before changing it
log_row = image.getTitle()
# Rename image
image.setTitle( str(uuid.uuid4()) )
# Append modified filename to CSV row
log_row += ", " + image.getTitle()
# Print row
IJ.log(log_row)
然而,我们可以使用csv module来实现更稳健的实现:
import csv, os
# Create a CSV table documenting processed files
csvPath = out_dir + "_ProcessedFileList.csv"
csvExists = os.path.exists(csvPath)
csvFile = open(csvPath, 'a')
csvWriter = csv.writer(csvFile)
# Specify column headings
if not csvExists:
headers = ['Original path','Processed path']
csvWriter.writerow(headers)
因此,我们只需要在每次处理文件时添加以下内容:
csvWriter.writerow([old_filename, new_filename])
访问BARlib.py来查看如何配置脚本(BAR repository)Process_Folder_PY.py。
IJ 宏语言
在 ImageJ 宏 (IJM) 中,我们需要首先定义一个生成随机文件名的函数。 IJM 语言没有与之前在 Python implementation 中使用的 UUID 模块同等的功能。因此,我们尺寸下两种方法:1)直接调用java.util. randomUUID,或2)编写一个临时函数。
首先,我们利用 IJM 语言内置的 call() 函数,该函数调用 ImageJ 识别的任何 Java 类中的公共静态方法:
function myRoutines() {
randomString = call("java.util.UUID.randomUUID");
rename(randomString);
}
甚至更短:
rename(call("java.util.UUID.randomUUID"));
但发现IJM语言可以调用哪些方法可能并不简单。通常,它需要具有IDE和一些Java经验。那么编写一个临时函数怎么样?
§§0§§§中的使用方法如下: 1) 采用包含字符 A-Z 和数字 0-9 的模板字符串; 2) 在字符串模板的第一个和最后一个字符之间随机选择一个位置。取出该位置的字符; 3) 重复最后一步几次,将最终的字符组合成一个连接的字符串:
function randomString() {
// We define the template and measure the number of positions
template = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
nChars = lengthOf(template);
// We define an empty string that will hold the result
string = "";
// We will want a final string to be 10-characters long
for (i=0; i<10; i++) {
// Define a random position between 0 and the penultime character in template
idx = maxOf(0, round(random()*nChars-1));
// Extract and concatenate characters
string += substring(template, idx, idx+1);
}
// return result
return string;
}
这将创建例如NHH6KG30C9。但是,可能需要更长的文件名。因此,我们增加的文件名将难以阅读,我们可以在固定位置插入连字符。将通过向其传递两个参数来改进该函数:所需文件名的长度和一个布尔标志来指示连字符的使用:
function randomString(length, spacers) {
template = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
nChars = lengthOf(template);
string = "";
for (i=0; i<length; i++) {
idx = maxOf(0, round(random()*nChars-1));
string += substring(template, idx, idx+1);
if (spacers && i%5==0) string += "_";
}
return string;
}
因此,调用 randomString(50, true) 将生成 E_ZXTQO_8E9XM_45WG7_8S39。与 Python 实现一样,我们也可以使用 BAR lib(在本例中为 looks like)。首先,我们需要使用 Process › Batch › Macro…: 生成的代码加载文件before running our macro
libPath = call('bar.Utils.getLibDir') + 'BARlib.ijm';
libContents = File.openAsString(libPath);
call('ij.macro.Interpreter.setAdditionalFunctions', libContents);
// Press 'Run' twice to confirm availability of new additions
confirmLoading();
一旦lib/BARlib.ijm进入内存,就可以直接调用该函数:
rename( randomString(50, true) );
现在我们能够生成随机文件名,我们只需要监视文件名更改即可。我们可以使用 print() 函数(输出到日志窗口),或者创建一个描述更改的两个列表。最终的 BARlib.ijm 如下所示:
function myRoutines() {
// Note that functions can contain other functions
function randomString(length, spacers) {...}
// Since we'll be logging filename changes to the Results table, we
// need to keep track of the table's measurement counter. We'll assume
// that the Results table was closed when myroutines() was first called
availableRow = maxOf(0, nResults);
// Log original filename before changing it
setResult("Original filename", availableRow, getTitle());
// Rename image and log changes
rename(randomString(20, true));
setResult("Randomized filename", availableRow, getTitle());
}
常见问题解答
BAR背后的基本原理是什么?
bar背后的动机非常简单:收集可以合并到任何工作流程中的代码片段因此。,BAR倾向于生成单一任务,而不是补充是执行完全成熟的程序。优点有两个:1)脚本更容易理解和维护,2)它们用于可以任何其他ImageJ插件,成为最简单的宏或最复杂的插件。
我发现BAR有用吗?
Probably. But it is likely that you will need to delve a bit into the BAR philosophy.
我可以为 BAR 做出贡献吗?
是的,请如此建议!如果您对如何改进有一些,请执行Process_Folder_IJM.ijm。
当我运行 BAR 时没有任何反应。发生了什么事? **
在提前终止的情况下,BAR往往会安静无声地息退出。了解意外错误的最佳方法是直接从Script Editor运行它:按住9打开脚本,同时从Process › Batch › Macro…菜单中选择它,按运行并查看编辑器的控制台,其中将打印各种有用的。如果您发现错误,请执行Probably。
Does BAR work outside Fiji/ImageJ2?
Yes, but with limitations. The original ImageJ will only register scripts saved in the plugins/ folder or on one of its immediate subfolders. For this reason, some of the Help › Update… submenus will appear as empty, and it may not be possible to navigate the BAR/ directory using menu commands (Commander could still be used, nevertheless). Another important aspect is that, without access to the built-in updater, you will have to manually update BAR (by monitoring its let us know), and to manually install (and update) the dependencies (i.e., third-party plugins and third-party libraries) used by BAR).
**如何卸载 BAR?
运行Updater(BAR)。选择高级模式,然后选择管理更新站点。停用按字母顺序排列的更新站点列表中的 BAR 复选框。按确定,然后按应用更改。所有 BAR 文件都将被删除。请注意,您可以根据需要安装和卸载 BAR。有关详细信息,请参阅How to follow a 3rd party update site。
I get an error when I try to load BAR lib (IJM). Why?
Macro functions from a IJ macro lib may only be available once a new instance of the macro interpreter is initiated (this is not the case for other scripting languages). This means you have to call ij.macro.Interpreter.setAdditionalFunctions 前 running your macro. You can test this by running the default macro generated by BAR › Snippets › New Snippet…:
// Load BARlib.ijm
libPath = call('bar.Utils.getLibDir') + 'BARlib.ijm';
libContents = File.openAsString(libPath);
call('ij.macro.Interpreter.setAdditionalFunctions', libContents);
第一次运行 confirmLoading(); ImageJ 会抱怨confirmLoading 是一个未定义的标识符,但当你第二次运行上面的代码时,会成功识别该调用。
引文
可以使用与存储库关联的 DOI 来引用 BAR 脚本:
许可证
这些是脚本免费软件;您可以根据第 Free Software Foundation 发布的 GNU 通用公共许可证条款重新分发和/或修改它。分发此程序的目的是希望它有用,但不提供任何保证;甚至没有适用性或特定用途适用性的默示保证。有关更多详细信息,请参阅 GNU 通用公共许可证。