Process images_file name into variable_macro

Hello,

I am newbie with creating macros.
Every folder contains 4 tiff files. I would like to pre-process these four images (each is a different channel_blue green red and magenta which I convert to gray) separately then count objects based on double-triple positive.

my problem is with obtaining the files from each folder (each file is named (directory name_CH# (1-4)) and assigning them a name to be able to work on with in the batch mode.

I found some hints online to use index function but I have no idea how to properly formulate that. Could someone please help?

Hi there,

I’m afraid that your description is rather confusing…

You want to get the files in each folder following this assumption:

So I will imagine that your folder hierarchy looks like this:

> Parent Folder
  -> Folder-1
    - Folder-1_CH1.tif
    - Folder-1_CH2.tif
    - Folder-1_CH3.tif
    - Folder-1_CH4.tif
  -> Folder-2
    - Folder-2_CH1.tif
    - Folder-2_CH2.tif
    - Folder-2_CH3.tif
    - Folder-2_CH4.tif

Then you can do this:

// Get the folders first
#@File directory (style="directory");

subfolders = getFileList( directory )

// Go through each folder
for ( i=0; i<subfolders.length; i++ ) {
	// Check that it is a folder
	if ( File.isDirectory( subfolders[i] ) ) {
		//Open sub images
		image_name = substring( subfolders[i] , 0, lengthOf( subfolders[i] ) -1 );

		// Open here
		open( directory+"/"+subfolders[i]+image_name+"_CH1.tif");

		// Process individual image here
	}
}

EDIT: As per @eljonco’s suggestion, I have replaced endsWith() with File.isDirectory(). Thanks for the info!

2 Likes

Thank you so much Oburri, that worked.