ImageJ

ImageJの使い方 1

How to use Imagej 1

ImageJはNIH imageをJavaで書きなおして開発されたもので、JavaはJVM(Java Virtual Machine)という仮想マシンの上で動作するためOSに依存しないというメリットがあります
ImageJ is developed by using Java. The software written by Java can work on any OS, owing to JVM.

Javaで書かれたImageJを実行するには、Java Runtime Environmentがシステムにインストールされている必要があるが、ImageJ bundled with 64-bit Java 8というJava 8ランタイム環境を内蔵している場合にはJava Runtime Environmentのインストールが不要です。
To run ImageJ written in Java, it is necessary to have the Java Runtime Environment installed on your system. However, if ImageJ is bundled with 64-bit Java 8, meaning it comes with the Java 8 runtime environment included, then installing the Java Runtime Environment is not required.


ImageJは医用画像の解析には定番のツールですが、あらかじめ様々なプラグインを追加したFijiもあります。
ImageJ is famous tool to analyze medical image. Do you know about Fiji which is installed several plugin to imagej in advance.

便利な機能がたくさん搭載されているのですが、起動がすこし重いです。
While it has many useful features, the slow startup is a minor drawback.

機会があったらまた、紹介したいと思います。
I will introduce it in the future.

では本題のImageJの使い方について説明していきます。
Let’s talk about main theme (how to use the Imagej)

初心者の方を想定していますので、初歩的なことを書いていきます。
I assume that the beginner read this article, so I write simply.

これを読めばImageJのファイルの入出力について理解することができます!
You can understand about Input/Output if you read this article.

何はともわれImageJのマニュアルを読むことが一番です。
Reading the  ImageJ manual is the best shortcut.

以下のサイトも同様に勉強になります。
The following sites can also be used for study in the same way.

https://imagejdocu.list.lu/gui/start
https://imagej.net/ij/docs/guide/146.html
https://seesaawiki.jp/w/imagej/
https://www.hm6.aitai.ne.jp/~maxcat/ImageJ.html

画像の開き方   How to open the image

1枚の画像の場合
   Open one image

 File→Open  または  ImageJにD&Dする
 
 以上です。でも、めんどくさいのでD&Dがオススメ!
File→Open or D&D into ImageJ
That’s all. However, I recommend to do by D&D method. It is easy.

複数枚の画像の場合
   Open several images

 File→Import→Image Sequence… で先頭の画像を開く
Open first image.


 または
 フォルダの中に画像をまとめておいて、フォルダをImageJにD&Dする
 ※ただし、これらは画像のサイズが同じである必要があります
Or
You archive several images in one folder, and you D&D that
folder into ImageJ. It is needed that images are same size (hxw)

Stack画像をそれぞれ別々のウィンドウに分ける
Divide into several windows

Image→Stacks→Stack to Imagesで選択中のStack画像が1枚の画像たちに分かれます
selected stack image divide into several images.

複数の画像をstackに戻す場合は
 When you want to archive many images to a stack.
 Image→Stacks→Image to Stack

関係ない画像も開かれていたら混ざってしまいますので注意
Note: If other image is opened, it is include in a stack.

特定の形式で開く
   Open specific type of the image

○Raw形式
 使用頻度は高いはず...。この場合は画像のサイズや形式(Unsigned IntegerやShort floatなど)を把握しておく必要があります。Interfile形式などであればヘッダーファイルを見てから開きます。
You need to know the information about image (size, number, type and so on). When open the Interfile format, you can see that information from meta (header) file.

上から順に
1.画像の形式(8bit,16bit,32bit
signed, unsigned …)(重要!)

type (important!)
2.幅 width
3.高さ height
4.画像の最初のピクセルまでのオフセット(大体0でOK、画像に関する情報がデータの頭に書き込まれている場合はその分をスキップする)
If the data about information about image, you need to skip it.
5.画像の枚数 The number of images
6.画像と画像のgap(大体0でOK)
gap ( do not need to change)
7.白を画素値0とするか white is 0 ?
8.リトルエンディアン形式かビッグエンディアン形式か(重要!)
Little endian or Big endian (important!)
9.フォルダ内の画像をすべて開くか
Put a check mark when open the all images in a folder.
10.大量の画像を読み込む場合に時間短縮。処理は保存されない。
To save time when you open many images. Processing is not saved.

画像が正しく開けなかった場合には1番と8番について間違いがないか確認してください。
もし、分からないならいろいろ変えてみるといいです
If you can not open image, please confirm that No,1 and No.8 are correct. You should try to change the condition (ex 8bit→16bit), when you do not know about image information.

○Text Image形式
 以外と使い道があります。画像は数値の塊ですので、エクセル(128×128のセル等)で保存した値で画像を作れます。エクセルで保存する際にはCSV(Comma Separated Value)形式で保存します。
このCSVファイルをText imageで開く場合、幅や高さを指定しなくとも開くことができます。
It is useful. Image is consisted by numeric. The file made by excel (ex 128×128) can be opened as a image. You save cell value by CSV format, and you can open it as a “text image”.

保存したText imageをエクセルにD&D
カラースケールでセルの値に応じて配色を変えると
When drop text image into excel, and use color scale function…

拡大してみると...
Zoom

それぞれのセルに数値が入っています

ちなみに複数のText imageをスタックとして開く場合にはマクロを使用するといいです。以下の文字列を使うといいです。
If you want to open many text images as a stack, you should use macro function.

dir = getDirectory("Choose directory");
list = getFileList(dir);
run("Close All");
setBatchMode(true);
for (i=0; i<list.length; i++) {
 file = dir + list[i];
 run("Text Image... ", "open=&file");
}
run("Images to Stack", "use");
setBatchMode(false);

上のコードの引用元はこちら。コードの意味はわからなくても使えます。大丈夫。
Above code is cited. You can use it even if you do not understand meaning of the code.

使い方は Plugins→New→Macro でマクロのウィンドウを開き
上のコードをコピー&ペーストする。
Macros→Run Macro で実行する。
※このとき、開きたいText Imageはひとつのフォルダにまとめておくこと。
 選択するのはText Imageではなく、それらが入っているフォルダを選択する
Note: It is needed that text images is placed in a folder and please choose that folder by macro. (not image)

○Interfile形式
 ImageJではプラグインを入れない限りInterfileをスムーズに開く方法はないと思います。ただしヘッダーファイルの中身を見てRaw形式で開くことができます。
You can not open Interfile format image easily without using plugin (maybe). But you can see the information from header file and you can open it as a Raw format.

Intefile形式は核医学データ用。Interfile3.3 では、拡張子が.hdrのヘッダーファイルと.imgの画像ファイルの2つからなる。
Interfile format is developed for nuclear medicine. Intefile 3.3 image data is consisted of two file.
.hdr(header data) .img(image data)

ヘッダーファイルの中はアスキー形式(メモ帳などで開ける)で画像の情報が載っています

ヘッダーファイル

○DICOM形式
 DICOM形式も問題なくD&Dで開くことができるが、核医学(PET)の画像を開いた時に画素値が大きくなる場合がある。この場合は、
 Edit→Options→DICOM→Open as 32bit floatにチェックを入れると解決する(はず)。
 You can open DICOM image as well. When you open PET image, pixel value may not be correct. Then you should put a check mark
“Open as 32bit float”.

画像の保存方法
   Save

保存方法はFile→Save as..→XXXX(形式を指定)で行います。
You can choose the format by ”File→Save as…→XXXX”

○Tiff形式
 32bit形式で保存することが可能。複数の画像をまとめてスタック形式で保存することができるので、使い勝手が非常にいい。容量は大きめ。
 You can save a image as a 32bit (short float) and it is archived into stack format. It is useful but data size is large.

○GIF形式、PNG形式
 イラストなどを保存する場合に適する。医用画像のようなグレースケールでは256色までしか保存できない。写真などではJPEG形式が優れる。ただし、透過色を使える。PNGはGIFよりも容量が大きくなる。
 This format is proper to a illustration image. Only 256 color can be used in gray-scale image (such as medical image) . JPEG is superior to save photograph. However, these format can use Transparent color. PNG data size is bigger than GIF.

○JPEG形式
 デジカメ等で使われて来たためもっとも有名な形式。最近はJPEG2000が出てきており、完全に劣るがまだまだ現役。グレースケールだと256色しか保存できない。
 JPEG is the most famous format. JEPG2000 (small size and high quality) is developed, but JPEG is used even now. Only 256 color can be used in gray-scale image.

○Text Image形式
 画素値を半角スペースで区切ってテキストデータとして保存する。Text ImageとしてImageJで開くことも可能であるし、エクセル等でも開くことができる。
 Pixel value is saved by separated by space. You can open it as a text image by ImageJ and excel.

○Raw data形式
 無圧縮で保存する。開く場合にはデータ形式や幅、高さ、枚数等を覚えておかないとダメ。
 No compression, so data size is large. You have to remember the information about image (size, number, type) when you open it.

○ZIP形式
 スタック画像を保存する場合など。ZIP形式で保存され、解凍すると中からTIFF画像が出てくる。ZIPに圧縮されてる分容量は小さくなる。
 You can use this format when you save stack image. You get TIFF image when unzip the zip file. Zip file is compressed, so data size is small.

○AVI形式
 スタック画像を動画として保存することができます。1秒間あたりのフレームを設定する必要があり、表示の速さが変わります。保存したAVIファイルはImageJにD&Dすることで開くことができます。
 You can save stack image as a movie file (AVI format). It is needed set a frame (frame/sec), and display speed and data size is changed. AVI file can be opened by D&D into ImageJ.

○XY Coordinates…
 選択範囲の四隅の座標を保存することができる。
 You can save the coordinate of four point (Upper Left, Upper Right, Lower Right, Lower Left)

〇Save XY Coordinates…
 上の保存方法とよく似ているが違うもの。Analyze→Tools→Save XY Coordinates…で保存する。画像(スタック画像も可)のX座標、Y座標、Z座標(枚数)と画素値を出力してくれる。画素値はグレースケールなら1つ、カラー画像ならRGBの3つ。ただし、この値はバックグラウンド領域のピクセルを除く。バックグラウンドのピクセル値は画像左上端のピクセル値となる。それぞれ1ピクセルの情報を1行に出力したテキストデータを吐き出す。Text Imageとはちょっと違った用途に使えるかも。
 This format can save three (or four) data, X, Y, Z(number of images), pixel value. Each value is written in a line in the text. You can use it for a little different purpose than “text image”.  

英語を追加するのめっちゃ疲れる!!
I’m feel tired to write English.
辞めるかも!!
I may be quit it !!