Linux 上的科学图像处理
ImageJ Fiji
![](/data/attachment/album/201711/29/064214rq07lbllcxquadvl.jpg)


在显示你的数据和工作方面我发现了几个科学软件，但是我不会涉及太多方面。因此在这篇文章中，我将谈到一款叫 ImageJ 的热门图像处理软件。特别的，我会介绍 [Fiji](https://imagej.net/Fiji)，这是一款绑定了一系列用于科学图像处理插件的 ImageJ 软件。


Fiji 这个名字是一个循环缩略词，很像 GNU 。代表着 “Fiji Is Just ImageJ”。 ImageJ 是科学研究领域进行图像分析的实用工具 —— 例如你可以用它来辨认航拍风景图中树的种类。 ImageJ 能划分物品种类。它以插件架构制成，海量插件可供选择以提升使用灵活度。


首先是安装 ImageJ （或 Fiji）。大多数的 ImageJ 发行版都可有该软件包。你愿意的话，可以以这种方式安装它，然后根据你的研究安装所需的独立插件。另一种选择是安装 Fiji 的同时获取最常用的插件。不幸的是，大多数 Linux 发行版的软件中心不会有可用的 Fiji 安装包。幸而，官网上的简单安装文件是可以使用的。这是一个 zip 文件，包含了运行 Fiji 需要的所有文件目录。第一次启动时，你只会看到一个列出了菜单项的工具栏。（图 1）


![](/data/attachment/album/201711/29/064226zthxuuy9b8eww9th.png)


*图 1. 第一次打开 Fiji 有一个最小化的界面。*


如果你没有备好图片来练习使用 ImageJ ，Fiji 安装包包含了一些示例图片。点击“File”->“Open Samples”的下拉菜单选项（图 2）。这些示例包含了许多你可能有兴趣做的任务。


![](/data/attachment/album/201711/29/064226h7biy1cf8z2284cc.jpg)


*图 2. 案例图片可供学习使用 ImageJ。*


如果你安装了 Fiji，而不是单纯的 ImageJ ，那么大量插件也会被安装。首先要注意的是自动更新器插件。每次打开 ImageJ ，该插件将联网检验 ImageJ 和已安装插件的更新。


所有已安装的插件都在“插件”菜单项中可选。一旦你安装了很多插件，列表会变得冗杂，所以需要精简你选择的插件。你想手动更新的话，点击“Help”->“Update Fiji” 菜单项强制检测并获取可用更新的列表（图 3）。


![](/data/attachment/album/201711/29/064229rz22l3sbtuo5r82w.png)


*图 3. 强制手动检测可用更新。*


那么，现在，用 Fiji/ImageJ 可以做什么呢？举一例，统计图片中的物品数。你可以通过点击“File”->“Open Samples”->“Embryos”来载入示例。


![](/data/attachment/album/201711/29/064229pah5d6s6vdyze6v7.jpg)


*图 4. 用 ImageJ 算出图中的物品数。*


第一步给图片设定比例，这样你可以告诉 ImageJ 如何判别物品。首先，选择在工具栏选择线条按钮。然后选择“Analyze”->“Set Scale”，然后就会设置比例尺包含的像素点个数(图 5)。你可以设置“known distance ”为 100，单元为“um”。


![](/data/attachment/album/201711/29/064229e7yzy207nnm4i79m.png)


*图 5. 很多图片分析任务需要对图片设定一个范围。*


接下来的步骤是简化图片内的信息。点击“Image”->“Type”->“8-bit”来减少信息量到 8 比特灰度图片。要分隔独立物体点击“Process”->“Binary”->“Make Binary”以自动设置图片门限。(图 6)。


![](/data/attachment/album/201711/29/064231lm5yt8cy5y90mcyt.png)


*图 6. 有些工具可以自动完成像门限一样的任务。*


图片内的物品计数前，你需要移除像比例尺之类的人工操作。可以用矩形选择工具来选中它并点击“Edit”->“Clear”来完成这项操作。现在你可以分析图片看看这里是啥物体。


确保图中没有区域被选中，点击“Analyze”->“Analyze Particles”来弹出窗口来选择最小尺寸，这决定了最后的图片会展示什么（图 7）。


![](/data/attachment/album/201711/29/064232ehejf64eted952b6.png)


\*图 7. 你可以通过确定最小尺寸生成一个缩减过的图片。 \*


图 8 在总结窗口展示了一个概览。每个最小点也有独立的细节窗口。


![](/data/attachment/album/201711/29/064232a75n51wmtei1k1kz.png)


*图 8. 包含了已知最小点总览清单的输出结果。*


当你有一个分析程序可以工作于给定图片类型，你通常需要将相同的步骤应用到一系列图片当中。这可能数以千计，你当然不会想对每张图片手动重复操作。这时候，你可以集中必要步骤到宏，这样它们可以被应用多次。点击插件->“Macros”->“Record”，弹出一个新的窗口记录你随后的所有命令。所有步骤完成，你可以将之保存为一个宏文件，并且通过点击“Plugins”->“Macros”->“Run”来在其它图片上重复运行。


如果你有非常特定的工作步骤，你可以简单地打开宏文件并手动编辑它，因为它是一个简单的文本文件。事实上有一套完整的宏语言可供你更加充分地控制图片处理过程。


然而，如果你有真的有非常多的系列图片需要处理，这也将是冗长乏味的工作。这种情况下，前往“Process”->“Batch”->“Macro”，会弹出一个你可以设置批量处理工作的新窗口（图 9）。


![](/data/attachment/album/201711/29/064233bj1qrkkhhj9qs9jj.png)


*图 9. 对批量输入的图片用单一命令运行宏。*


这个窗口中，你能选择应用哪个宏文件、输入图片所在的源目录和你想写入输出图片的输出目录。也可以设置输出文件格式，及通过文件名筛选输入图片中需要使用的。万事具备之后，点击窗口下方的的“Process”按钮开始批量操作。


若这是会重复多次的工作，你可以点击窗口底部的“Save”按钮保存批量处理到一个文本文件。点击也在窗口底部的“Open”按钮重新加载相同的工作。这个功能可以使得研究中最冗余部分自动化，这样你就可以在重点放在实际的科学研究中。


考虑到单单是 ImageJ 主页就有超过 500 个插件和超过 300 种宏可供使用，简短起见，我只能在这篇短文中提出最基本的话题。幸运的是，还有很多专业领域的教程可供使用，项目主页上还有关于 ImageJ 核心的非常棒的文档。如果你觉得这个工具对研究有用，你研究的专业领域也会有很多信息指引你。




---


作者简介：


Joey Bernard 有物理学和计算机科学的相关背景。这对他在新不伦瑞克大学当计算研究顾问的日常工作大有裨益。他也教计算物理和并行程序规划。




---


via: <https://www.linuxjournal.com/content/image-processing-linux>


作者：[Joey Bernard](https://www.linuxjournal.com/users/joey-bernard) 译者：[XYenChi](https://github.com/XYenChi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# Image Processing on Linux

I've covered several scientific packages in this space that generate
nice graphical representations of your data and work, but I've
not gone in the other direction much. So in this article, I cover
a popular image processing package called ImageJ. Specifically, I am
looking at [Fiji](https://imagej.net/Fiji),
an instance of ImageJ bundled with a set of plugins
that are useful for scientific image processing.

The name Fiji is a recursive acronym, much like GNU. It stands for "Fiji Is Just ImageJ". ImageJ is a useful tool for analyzing images in scientific research—for example, you may use it for classifying tree types in a landscape from aerial photography. ImageJ can do that type categorization. It's built with a plugin architecture, and a very extensive collection of plugins is available to increase the available functionality.

The first step is to install ImageJ (or Fiji). Most distributions will have a package available for ImageJ. If you wish, you can install it that way and then install the individual plugins you need for your research. The other option is to install Fiji and get the most commonly used plugins at the same time. Unfortunately, most Linux distributions will not have a package available within their package repositories for Fiji. Luckily, however, an easy installation file is available from the main website. It's a simple zip file, containing a directory with all of the files required to run Fiji. When you first start it, you get only a small toolbar with a list of menu items (Figure 1).

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif1.png)

Figure 1. You get a very minimal interface when you first start Fiji.

If you don't already have some images to use as you are learning to work with ImageJ, the Fiji installation includes several sample images. Click the File→Open Samples menu item for a dropdown list of sample images (Figure 2). These samples cover many of the potential tasks you might be interested in working on.

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif2.jpg)

Figure 2. Several sample images are available that you can use as you learn how to work with ImageJ.

If you installed Fiji, rather than ImageJ alone, a large set of plugins already will be installed. The first one of note is the autoupdater plugin. This plugin checks the internet for updates to ImageJ, as well as the installed plugins, each time ImageJ is started.

All of the installed plugins are available under the Plugins menu item. Once you have installed a number of plugins, this list can become a bit unwieldy, so you may want to be judicious in your plugin selection. If you want to trigger the updates manually, click the Help→Update Fiji menu item to force the check and get a list of available updates (Figure 3).

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif3.png)

Figure 3. You can force a manual check of what updates are available.

Now, what kind of work can you do with Fiji/ImageJ? One example is doing counts of objects within an image. You can load a sample by clicking File→Open Samples→Embryos.

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif4.jpg)

Figure 4. With ImageJ, you can count objects within an image.

The first step is to set a scale to the image so you can tell ImageJ how to identify objects. First, select the line button on the toolbar and draw a line over the length of the scale legend on the image. You then can select Analyze→Set Scale, and it will set the number of pixels that the scale legend occupies (Figure 5). You can set the known distance to be 100 and the units to be "um".

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif5.png)

Figure 5. For many image analysis tasks, you need to set a scale to the image.

The next step is to simplify the information within the image. Click Image→Type→8-bit to reduce the information to an 8-bit gray-scale image. To isolate the individual objects, click Process→Binary→Make Binary to threshold the image automatically (Figure 6).

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif6.png)

Figure 6. There are tools to do automatic tasks like thresholding.

Before you can count the objects within the image, you need to remove artifacts like the scale legend. You can do that by using the rectangular selection tool to select it and then click Edit→Clear. Now you can analyze the image and see what objects are there.

Making sure that there are no areas selected in the image, click Analyze→Analyze Particles to pop up a window where you can select the minimum size, what results to display and what to show in the final image (Figure 7).

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif7.png)

Figure 7. You can generate a reduced image with identified particles.

Figure 8 shows an overall look at what was discovered in the summary results window. There is also a detailed results window for each individual particle.

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif8.png)

Figure 8. One of the output results includes a summary list of the particles identified.

Once you have an analysis worked out for a given image type, you often need to apply the exact same analysis to a series of images. This series may number into the thousands, so it's typically not something you will want to repeat manually for each image. In such cases, you can collect the required steps together into a macro so that they can be reapplied multiple times. Clicking Plugins→Macros→Record pops up a new window where all of your subsequent commands will be recorded. Once all of the steps are finished, you can save them as a macro file and rerun them on other images by clicking Plugins→Macros→Run.

If you have a very specific set of steps for your workflow, you simply can open the macro file and edit it by hand, as it is a simple text file. There is actually a complete macro language available to you to control the process that is being applied to your images more fully.

If you have a really large set of images that needs to be processed, however, this still might be too tedious for your workflow. In that case, go to Process→Batch→Macro to pop up a new window where you can set up your batch processing workflow (Figure 9).

![](http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1000009/12172fijif9.png)

Figure 9. You can run a macro on a batch of input image files with a single command.

From this window, you can select which macro file to apply, the source directory where the input images are located and the output directory where you want the output images to be written. You also can set the output file format and filter the list of images being used as input based on what the filename contains. Once everything is done, start the batch run by clicking the Process button at the bottom of the window.

If this is a workflow that will be repeated over time, you can save the batch process to a text file by clicking the Save button at the bottom of the window. You then can reload the same workflow by clicking the Open button, also at the bottom of the window. All of this functionality allows you to automate the most tedious parts of your research so you can focus on the actual science.

Considering that there are more than 500 plugins and more than 300 macros available from the main ImageJ website alone, it is an understatement that I've been able to touch on only the most basic of topics in this short article. Luckily, many domain-specific tutorials are available, along with the very good documentation for the core of ImageJ from the main project website. If you think this tool could be of use to your research, there is a wealth of information to guide you in your particular area of study.

[Load Disqus comments](https://www.linuxjournal.com/content/image-processing-linux#disqus_thread)