Skip to content

Automation

(2022.6.24 only description, no image)

Introduction

In 2022.Jul, I made ImageJ macros and Excel VBA for automatic processing of serial images obtained by CoMBI. According to Release Note of ImageJ, many bugs were fixed in "Image Sequence" from version 1.53d (2020.Aug) to 1.53p (2022.Mar). Many thanks to developers! Automatic process includes following steps:

  1. Resize, ImageJ /縮小
  2. Image registration, ImageJ and Excel VBA /ズレ補正、補正値の修正
  3. Crop, Grayscale, ImageJ /切り抜き、グレースケール

All macro save not only serial images but also "a work log" containing image information, path, values used for processing, date and time of processing. I hope the work log contributes to improve the reproducibility of experiments.

Videos showing how these macro work are available on Twitter.

2022年5月、連続画像の処理を自動化しようと思い立ち、2022年6月末、ImageJ macroとExcel VBAのファイルを完成させました。ImageJによる自動化が可能になったのは、2020年8月 v1.53d 〜2022年3月 v1.53pに行われたImageJアップデートのおかげのようです。アップデートを経て、ImageJ macroが連続画像を扱えるようになりました。開発者の方々に感謝いたします。自動化できた処理は、画像の縮小、ズレ補正、補正値の修正、切り抜き、グレースケール変換です。加えて、作業記録を保存できます。作業記録には、使用したデータ情報や、切り抜き位置などの処理情報が含まれます。実験の再現性向上にお役に立てていただければ幸いです。

Automation
Overview of image processing

Download ImageJ macro and Excel VBA


Download site: ImageJ macro and Excel macro for CoMBI, GitHub


ImageJ macros and Excel VBA are available at GitHub(Since 2022.6). There are 9 files but you can process using only 4 essential files. I developed these files using Intel Mac and Apple Silicon Mac, and validated using on Windows11 (MS Surface, 2022.7 Thank you, HS!) and Windows10 via Intel-mac's bootcamp (2022.6). FIJI on Winows11 can't run CoMBI macros; neither CoMBI_Crop1_ISApplier_Crop2_CopyLog.ijm or CoMBI_Crop1_ISApplier_Crop2_SelectLog.ijm. Original ImageJ is recommanded for windows11 users (Thank you, Dr.M 2024.2).

Step FIles Priority Compatibility
1. Resize CoMBI_Resize.ijm 1. Essential ImageJ_win,mac
2. Image Stabilizer CoMBI_ImageStabilizer_2x.ijm 2. Essential ImageJ_win,mac
2. Image Stabilizer CoMBI_ImageStabilizer_1x1.ijm ImageJ_win,mac
2. Image Stabilizer IS_Log_Validator.xlsm 2. Essential Excel_win,mac
3. Crop, IS_Applier CoMBI_Crop1_ISApplier_Crop2_CopyLog.ijm FIJI_mac_intel, FIJI_mac_ARM
3. Crop, IS_Applier CoMBI_Crop1_ISApplier_Crop2_SelectLog.ijm 3. Essential ImageJ_win,mac
3. IS_Applier CoMBI_IS_Applier_CopyLog.ijm FIJI_mac_intel, FIJI_mac_ARM
3. IS_Applier CoMBI_IS_Applier_SelectLog.ijm ImageJ_win,mac
3. Crop, Invert CoMBI_Crop_Invert.ijm ImageJ_win,mac

For download, find "Code" button and click "Download ZIP". All files are contained in a single folder and downloaded.

GitHub

ImageJマクロと、Excelマクロをダウンロードしてください。こちらから>>> GitHub CoMBI_ImageJ<<< 9つのファイルがありますが、最低限必須の4つで画像処理できます。他は単機能のマクロファイルです。

ImageJ app to be used



ImageJ 1.53s (2022.7) or newer is recommended, since there is a difference between ImageJ 1 and FIJI/ImageJ, when opening text files. ImageJ 1 can open text file directly, while FIJI/ImageJ cannot.

  • Apple silicon mac: use ImageJ for ARM(1.53s, 2022.6), and ImageJ macros with "SelectLog", and Excel VBA. After installation of ImageJ, go to Help>Update ImageJ... to make the app latest (1.53s, 2022.7). FIJI (2.3.0/1.53q) is not recommended since it needs macro with "CopyLog", which is unconvenient rather than SelectLog (2022.6).

  • Intel mac: use ImageJ (1.53s, 2022.6), ImageJ macros with "SelectLog", and Excel VBA. After installation of ImageJ, go to Help>Update ImageJ... to make the app latest (1.53s, 2022.7). FIJI (2.3.0/1.53s) is not recommended since it needs macro with "CopyLog", which is unconvenient rather than SelectLog (2022.6).

  • Windows: Use ImageJ (1.53s, 2022.6), ImageJ macros with "SelectLog", and Excel VBA. After installation of ImageJ, go to Help>Update ImageJ... to make the app latest (1.53s, 2022.7). Currently, FIJI for Windows cannot run macros for CoMBI. ImageJ app should NOT be installed into "Program Files" folder. Please, follow instruction on the official site.

  • Linux: (Sorry, I do not have linux machine.) Try ImageJ 1.* and "SelectLog" at first. LibreOffice accepts Excel VBA, but the Excel file for CoMBI still have some bugs, due to uncompatibility of some commands.

  • Excel VBA can not accept path written in local languages, for example Japanease Hiragana or Kanji. Make sure that path of serial images and log files are written only with alphabet, numbers, and other acceptable characters.

WindowsでもMacでも、ImageJ本家の利用をお勧めします。FIJI版ではテキストファイルを扱えない場合があるためです(2022.7)。ImageJマクロは、いったんすべてのファイルをGitHubからダウンロードした後、各自のパソコン環境に合わせたファイルを選択して利用してください。
GitHubからは、Excel VBAもいっしょにダウンロードされます。Excel VBAは、実行する際にパス(ファイル名やフォルダ名)に日本語が入っていると、エラーがでます。OSによって異なるかも知れませんが、すくなくともmacOSではパスに日本語が入らないようにします。パス内の日本語を回避する方法は、「検証したいログファイルは、アルファベットのファイル名をつける」および「ExcelVBAで検証したいログファイルは、ユーザ名直下のドキュメントまたはデスクトップに置く」ことです。

Setting up ImageJ

  • Downloaded installer may contains older version, thus update ImageJ to latest version by Help> Update.

  • Plugins "Image Stabilizer" and "Image Stabilizer Log Applier" are needed. Download .class files from ImageJ, Image Stabilizer. On mac, a folder "plugins" is unvisible but you can find it by; Open "Finder", find /Application/ImageJ.app, Right click over the icon, and select Show packege contents. Then, go to /plugins, and add downloaded class files. Restart ImageJ before use. The shortcuts of macros for Image Stabilizer will appear in Menubar > plugins.

  • Download ImageJ macro for CoMBI (above), and add these ijm files in ImageJ/"plugins" folder (Not "macros" folder). On mac, a folder "plugins" is unvisible but you can find it by; Open "Finder", find /Application/ImageJ.app, Right click over the icon, and select Show packege contents. Then, go to /plugins, and add downloaded and selected ijm files. Restart ImageJ before use. The shortcuts of macros for CoMBI will appear in Menubar > plugins.

  • Set memory for imagej, max 75% of total memory. Edit> Options> Memory & Threads...> Maximum Memory

  • Set JPEG compression rate. The value 100 is recommended. Edit> Options> Input/Output...> JPEG quality (0-100) I prefer to use JPEG to save disc space, and JPEG is acceptable by 3D slicer, Horos. The value 100 reduces data size into about 12%, seems to keep enough quality as morphological data by CoMBI.

ImageJは、2022年3月以降の新しいバージョンを使ってください。1.53pより新しい版に対応します。インストールしたらまずHelp>Updateをして最新版にしてください。インストーラは古い場合があるためです。Image Stabilizerプラグインの追加と、CoMBI用macroファイルのプラグインへの追加をしてください。ImageJで使用するメモリ量、JPEG圧縮率(低圧縮)の設定を行ってください。

Procedure

  1. Prepare serial images in JPEG, and a scale image.
  2. {ImageJ} Run plug-in "CoMBI_Resize"
  3. {ImageJ} Run plug-in "CoMBI_ImageStabilizer_2x"
  4. {Excel} Validate ImageStabilizer Log values using Excel VBA "IS_Log_Validator.xlsm"
  5. {ImageJ} Run plug-in "CoMBI_Crop1_ISApplier_Crop2_SelectLog"

Description of each macro files

CoMBI_resize.ijm (Essential)

Automate Resizing and reducing process.

Data:

  • a folder containing serial image
  • a scale image (reference image)

Macro runs:

  1. Select a folder containing serial image.
  2. Calculate the pixel size of the scale image (reference image) or Use the pixel size of the previous experiment.
  3. Plan the resizing process. By default, RGB series of 5μm/pixel, 10μm/pixel, and 20μm/pixel are created. Custom pixel sizes can also be selected. Grayscale series (8-bit, inverted) can be created optionally in addition to RGB series.
  4. Create folders to store the resized images.
  5. Resize the serial images as selected above.
  6. All information (log window) will be saved as a text file, hoping that it will help the researcher to handle the dataset and reproduce the experiment.

CoMBI_ImageStabilizer_2x.ijm (Essential)

Automate Image Registration process. Fully automated.

Data Preparation:

  • a folder containing serial image

Run Macro "CoMBI_ImageStabilizer_2x.ijm"

  1. Select items to be saved. "2 log files only"(default) or "Images also"
  2. Select a folder containing serial image.
  3. Run Image Stabilizer 2 times automatically;
    1. Run plugin; Image Stabilizer. From first to last image (Forward).
    2. Save log (essential), and images (optional)
    3. Run plugin; Image Stabilizer. From last to first image (Backward).
    4. Save log (essential), and images (optional)

CoMBI_ImageStabilizer_1x1.ijm

Automate Image Registration process, step by step.

Preparation:

  • a folder containing serial image

Macro runs:

  1. Select a folder containing serial image.
  2. Run plugin; Image Stabilizer. From first to last image (Forward).
  3. Review stabilized series.
  4. If "Success" in forward stabilization, save images and log, and end macro.
  5. If "False" in froward stabilization, try again from last to first image (Backward).
  6. Review stabilized series.
  7. If "Success" in backward stabilization, save images and log, and end macro.
  8. If "False" in backward stabilization, save log only.
  9. Save work log.

IS_Log_Validator.xlsm (Essential)

Automate middle part of Image Registration process; Correct log file. When open this file by Excel, the app will ask "Enable macros", and may ask "Permission of foler access". There is 5 sheets in the xlsm file. Follow instruction in the sheet from sheet1 to 4. In each sheet, a initialize button is available. The button can clear all value of the sheet and initialize all functions. You can use the initialize button in case you accidentally modify the xlsm file.

エクセルを開くとき、マクロを有効にします。macOSではでてきたメッセージで「マクロを有効にする」ボタンをおすだけです。Windowsの場合、「ファイル>オプション>セキュリティーセンター>セキュリティーセンターの設定>すべてのマクロを有効にする」
このExcel VBAを実行する際に、ログファイルのパス(ファイル名やフォルダ名)に日本語が入っていると、エラーがでます。最後のステップで修正ログを保存するとき。OSによって異なるかも知れませんが、すくなくともmacOSではパスに日本語が入らないようにします。検証したいログファイルはアルファベットのファイル名がついていること、および、ExcelVBAファイルによる検証時にはログファイルをユーザ名直下の「ドキュメント」や「デスクトップ」などに置くことで、パス内の日本語を回避してください。
エクセルファイルには5つのタブがあります。順に操作していきます。

Preparation:

  • Log file Forward
  • Log file Backward

Excel:

  1. Sheet1: Import Log_Forward
  2. Sheet2: Import Log_Backward
  3. Sheet3: (Just take a look values in validation.)
  4. Sheet4: Create and save validated Log files. Up to 4 kinds of log files can be created using folded values.
  5. Sheet5: (Macro uses here during creation of log files.)

CoMBI_Crop1_ISAplier_Crop2_CopyLog.ijm

For FIJI on intel mac. Automate last part of Image Registration process. The macro run crop, Image Stabilizer by corrected log file, crop again, and create grayscale series. All steps are selectable.

Preparation:

  • serial images
  • Log file
  • Copy log file values using TextEdit.app (Mac) etc.

Macro runs:

  1. Select serial images and open.
  2. Import log values on the clipboard.
  3. Crop by a rectangle.
  4. Image Stabilizer Log Applier
  5. Crop again
  6. Create grayscale series
  7. Save work log

Created series are saved in folders with "original name + additional charactors below" as required.

  1. _Crop1
  2. _IS
  3. _Crop1_IS
  4. _Crop2
  5. _IS_Crop2
  6. _Crop1_Crop2
  7. _Crop1_IS_Crop2
  8. _Gray
  9. _Crop2_Gray
  10. _IS_Gray
  11. _Crop1_Gray
  12. _IS_Crop2_Gray
  13. _Crop1_IS_Gray
  14. _Crop1_Crop2_Gray
  15. _Crop1_IS_Crop2_Gray

CoMBI_Crop1_ISAplier_Crop2_SelectLog.ijm (Essential)

For ImageJv1.* and FIJI on ARM mac. Automate last part of Image Registration process. The macro run crop, Image Stabilizer by corrected log file, crop again, and create grayscale series. All steps are selectable.

Preparation:

  • serial images
  • Log file

Macro runs:

  1. Select serial images and open.
  2. Select corrected log file and open.
  3. Crop by a rectangle.
  4. Image Stabilizer Log Applier
  5. Crop again
  6. Create grayscale series
  7. Save work log

Created series are saved in folders with "original name + additional charactors below" as required.

  1. _Crop1
  2. _IS
  3. _Crop1_IS
  4. _Crop2
  5. _IS_Crop2
  6. _Crop1_Crop2
  7. _Crop1_IS_Crop2
  8. _Gray
  9. _Crop2_Gray
  10. _IS_Gray
  11. _Crop1_Gray
  12. _IS_Crop2_Gray
  13. _Crop1_IS_Gray
  14. _Crop1_Crop2_Gray
  15. _Crop1_IS_Crop2_Gray

CoMBI_IS_Applier_CopyLog.ijm

Automate last part of Image Registration process; Only apply corrected log file.

Prepararion

  • Open validated log text file with TextEdit.app (Mac). Select all (Command+a), Copy (Command+c) to keep value system clipboard.
  • "a folder containing serial image"

Macro runs:

  1. Then, Run automatically
  2. File>New>System clipboard. to reveal values in FIJI/ImageJ
  3. Open sequence images on system memory. NOT virtual stack, since IS supports virtual stack "partially" in current ImageJ.
  4. Run plugin: Image_Stabilizer_Log_Applier
  5. Save as Image Sequence in new folder with _IS_Validated
  6. Close images and log.

CoMBI_IS_Applier_SelectLog.ijm

Automate last part of Image Registration process; Only apply corrected log file.

Preparation:

  • Log file
  • Serial images

Macro runs:

  1. Select a Log file
  2. Select a folder containing serial image
  3. Open sequence images on system memory. NOT virtual stack, since IS supports virtual stack "partially" in current ImageJ.
  4. Run plugin: Image_Stabilizer_Log_Applier
  5. Save as Image Sequence in new folder with _IS_Validated
  6. Close images and log.

CoMBI_Crop_Invert.ijm

Automate croping serial images, and/or converting to 8-bit inverted series. 8-bit inverted images will be used for volume rendering.

Preparation:

  • Serial images

Macro runs:

  1. Select a folder containing serial image
  2. Open sequence images as virtual stack
  3. Crop by a drawn rectangle.
  4. Save as Image Sequence in new folder, and work log.