How to automatically open a stack of raw images using a macro without having the image dialog pop up?

Hi all,

I have several stacks of raw images, which every stack contains 256 images, and I want to automatically open the images of each stack, and then do some analyses on them.
The macro code is as follows:

inputAddress = “E:\Sara\…\”
list = getFileList(inputAddress);
for (i = 0; i < list.length; i++){
open(inputAddress+list[i]);

}

But, for every ‘i’, the image dialog pop up and I should set the image type, image height, image width, etc, and then another dialog appears that says that are you sure that you want to open all 256 images, and I have to click yes!

What should I do to get rid of these two dialog boxes?

Best regards,
Sara

Hi @sara_sh,

Have you tried to record (Plugins>Macros>Record…) what is happening when you fulfill the dialogs ? Mybe your answers are scriptable.

Nico

Hi Nico,

yeah, I checked that, but couldn’t find somehing usefull. When I try to manually open the file this message appear on the record window:
open(“C:/ImageJ/OCTAufnahme_09_10_19/20191009_15-34-12-868TapeTissueHole_M02_processed.raw”);
which is only the address of my file.

Hi @sara_sh,

Have you tried to open the image with Plugins>Bio-Formats>Bio-Formats importer ?
And could you share one of your images in order that the community could experiment your problem.

Nico

I could not upload the RAW format, but I have uploaded the tif version.
and I cannot open my files using Bio-Formats importer!

However, I can open my files using File->Import->Raw, and see this message on the recorder window:
run(“Raw…”, “open=C:/ImageJ/OCTAufnahme_09_10_19/20191009_15-34-12-868TapeTissueHole_M02_processed.raw image=[16-bit Signed] width=832 height=512 number=256 little-endian”);
But it is just for one file. I don’t know how to put it in my for loop so that I can automatically open each file inside the address folder. For a single image, I use this piece of code:
inputAddress = “E:\Sara\…\”
list = getFileList(inputAddress);
for (i = 0; i < list.length; i++){
open(inputAddress+list[i]);

}
but for stacks it doesn’t work.

Give a try to

inputAddress = “E:\Sara\…\”
list = getFileList(inputAddress);
for (i = 0; i < list.length; i++){
   run("Raw…", "open=" + inputAddress+list[i] + " image=[16-bit Signed] width=832 height=512 number=256 little-endian");
…
}

This should work (if all your raw files have the same size)
(be careful when doing copy/paste, the " " of the internet browser may not the same as the ones in imageJ)

Nico

Thank you so much. That solves the problem with the image dialog, but I still see the second dialog box for each file. After opening each file, a process stack dialog box apears, which says:
“Process all 256 images? There is no Undo if you select “Yes”.”
And I should press “yes” every single time, which in my case means 51 times, beacuse I have 51 stacks to analyse. Do I also have any idea that how can I solve this problem?

Thanks a lot
Sara

Which process do you use ? Because most of the time, the processing of a stack can be scripted.

Nico

here is the complete macro code:

input = getDirectory(“Choose a Directory”);
list = getFileList(input);
m = 0;

Y = newArray(list.length);

for (i = 0; i < list.length; i++){
	run("Raw...", "open=" + input+list[i] + " image=[16-bit Signed] width=832 height=512 number=256 little-endian");
	
	getRawStatistics(nPixels, mean);
	W = getWidth();
	H = getHeight();
	b = 0;


	for (j=0; j<H; j++) {
		 for (k=0; k<W; k++) {
 		 p = getPixel(k,j);
 		 t = (p-mean)*(p-mean);
 		 b += t;
 		 
		}
	}
	
Y[i] = b;
	
		
	
	if(m<b){
		m=b;
		n=i+1;
	}
	else{}	
			
	close();
	}

	
	X = Array.getSequence(list.length);

	Plot.create("", "Image Number", "Sum of the square of the intencities")
	Plot.add("line", X, Y);
	
    print("The infocus image is, the image number:"+n);