Snippets

Dave Mason Rename images based on titles [https://forum.image.sc/t/rename-multiple-images-based-on-their-present-titles/35987]

Created by Dave Mason
//-- close any open files
close("*");
//-- clear the log
print("\\Clear");
//-- open any files here
newImage("ch00", "8-bit noise", 200, 200, 1);
newImage("ch01", "8-bit noise", 200, 200, 1);
newImage("ch02", "8-bit noise", 200, 200, 1);
newImage("ignore", "8-bit noise", 200, 200, 1);
newImage("dm", "8-bit noise", 200, 200, 1);

//-- How many images are open?
numImages=nImages;
print("Open Images: "+numImages);

//-- loop through open images and check names
for (i=0;i<numImages;i++){
	//-- selectImage uses 1-indexed numbers
	selectImage(i+1);
	print(getTitle());
	
	//-- pull the image title and check for the substring.
	//-- indexOf returns -1 for no string found
	title=getTitle();
	if (indexOf(title, "ch00")>-1){rename("GFP");}
	if (indexOf(title, "ch01")>-1){rename("RFP");}
	if (indexOf(title, "ch02")>-1){rename("CFP");}
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.