Splitting 4-color TIFF images into single color, change to grey scale and save

Hi all,

I want to split 4-color pictures from a confocal microscope into all 4 channels, transform the single-color pictures into grey scale and save all pictures.
The idea is, that I’ll have a folder with e.g. 10 4-color pictures, run the macro with this folder and get 10 sub-folders for each 4-color picture with four single-color pictures in them.

Afterwards I’d analyse these pictures and compare them regarding protein expression via CellProfiler.

Since I am new with this coding (and it should be rather simple in my case), I was only able to get the following stuff going:

// make ImageJ/Fiji clean 	
roiManager("Reset");							// reset ROI manager
run("Clear Results");							// and the results table
run("Close All");							// close every image

path = getDirectory("Select A folder");					// Then ask the user to select a folder
fileList =  getFileList(path);						// and  get the list of file within

savingDir = path+"Saving_Split_Channels"+File.separator;
File.makeDirectory(savingDir);						//  create a Folder to save files

for (fileNumber = 0 ; fileNumber < lengthOf(fileList) ; fileNumber++){	//  for every file in the folder
		open(fileList[fileNumber]);				// open the image 
		title = getTitle();					// get the image title	
		
		run ("Split Channels"); 			// split the images in 4 single channel images
		run ("Grays");	// transform into grey
		saveAs ("tiff", savingDir+getTitle);				// save every picture

		run("Close All");					//close every image
	}
}

For now, this macro gives me an Error in the end: "File is not in a supported format, a reader plugin is not available, or it was not found."
I don’t know what to do with this error.
ATM, it saves one of the four single-color pictures, that is already in “Grey” by default.

I am also not completely sure if “Grays” is the correct command for transforming the pictures into gray-scale. It’s the option: Image>Lookup Tables>Grays

Thank you very much in advance!

Welcome to the forum, @Peter3000. :smile:

Sounds like you want to save all four channels, not just the first. So you need to write something like:

		run ("Split Channels"); 			// split the images in 4 single channel images
		while (nImages > 0) {
			run ("Grays");	// transform into grey
			saveAs ("tiff", savingDir+getTitle);				// save every picture
			close();
		}

Probably there are non-image files also in the directory you chose. Easiest solution is to filter the file list by extension. See Templates :arrow_forward: ImageJ 1.x :arrow_forward: Examples :arrow_forward: Process Folder (IJ1 Macro) in the Script Editor. See also the Flexible option section of the batch processing guide.

Should be correct, I think. You used the Macro Recorder to find that out, right? It’s much easier than guessing!