Use macro to batch add channels from another file with similar file name

Dear All,

My purpose is to batch add channels from another file with the similar file name.
My original file name is “1.tif” and the file I want to add is named "1_D3D.dv"
The following are the strings I had wrote.

title = getTitle();
open("J:\\Membrane potential\\D3D\\" + title + "_D3D.dv");

After execute the macro, Fiji showed "File is not in supported format, a reader plugin is not available, or it was not found. 1.tif_D3D.dv"
The original file “1.tif” was gotten by another macro wrote by myself to crop, process from another file named "1.dv"
I am very sure the resolution, the stack size and the bit depth in “1.itf” are all the same as in "1_D3D.dv"
Could anyone help me to overcome this problem?
Your help will be highly appreciated.

Sincerely,
Peggy

Peggy,

most likely it is the file suffix “.dv” that is not recognized. If you are sure that your files are TIF-files you could simply change the suffix to “.tif”.

I would try “by hand” first and if it works, look for an automatic way of changing the suffix. If you use the ImageJ-macro language you may have a look at the “File”-routines.

HTH

Herbie

Your macro is trying to open the file 1.tif_D3D.dv which I assume does not actually exist. The error message is unfortunately confusing in this case.

To do the rename generally and efficiently I would suggest using the replace function:

tifName = getTitle();
dvName = replace(tifName, ".tif", "_D3D.dv");

If your renames are not this general you can also look at stripping the extension off with substring and indexOf calls

1 Like

Peggy,

if you still have problems reading “.dv”-files you may have a look at “Bio-Format”, an ImageJ-plugin that may be able to open such files, at least the “Bio-Format”-website tells us that it can.

HTH

Herbie

The open function should use Bio-Formats under the hood, because Bio-Formats is the last thing tried by ImageJ 1.x’s built-in HandleExtraFileTypes.

But @Peggy, you can also call Bio-Formats explicitly from a macro. Just use the Macro Recorder to record the File :arrow_forward: Import :arrow_forward: Bio-Formats command with desired settings.

Dear Herbie, hinerm, and ctruedn,

Thank you for the answer. Because I am using Fiji, the files with dv format can be opened directly through File\Open.
The question is that Fiji always read the suffix “.tif” as one part of the file name. After the function “getTitle”, the file name is read “1.tif” instead of “1”.
Now, I found a simple string executed in the Command Prompt.
Just type “Rename J:\Membrane potential\Result*.tif *”, to trim off the tif suffix in the Result folder.
Then the string in the second line can be done well.

I am not an IT worker. Could anyone help to incorporate the function in the Command Prompt in the Fiji macro?
Thank you all very much.

Peggy

Hi everyone,
Here another problem came out.
Because the window “Bio-Formats Import Options” prompt out for every image in the batch process and disrupt the process, I change my second line from
open(“J:\Membrane potential\D3D\” + title + “_D3D.dv”);
to the following
run(“Bio-Formats Importer”, “open=[“J:\Membrane potential\” + title + “_D3D.dv”] autoscale color_mode=Default open_all_series view=Hyperstack stack_order=XYCZT”);
However, it showed “)” expected in line 2 in the macro error.
Could anyone correct this line for me?
Thank you!

Peggy

Peggy,

replacing the suffix has been explained by Mark Hiner (hinerm) above. Does his approach work for you?

Herbie

Peggy,

regarding your second question you may try:

tifName = getTitle();
dvName = replace(tifName, ".tif", "_D3D.dv");
path = "J:\\Membrane potential\\" + dvName;
run("Bio-Formats Importer", "open=[" + path + "] autoscale color_mode=Default view=[Standard ImageJ] stack_order=Default");

HTH

Herbie

1 Like

Dear Herbie,

Now I realize what hinerm meant and the function of replace.
In addition, what you wrote works well with the modification from “standard Image J” to “Hyperstack” in the view option.
Now, I can finally process hundred images with the macro.
Thank you all!

Best Regards,
Peggy