http://imagej.273.s1.nabble.com/Finding-files-based-on-a-substring-tp5020882p5020884.html
then create the name of the corresponding background image out of it.
> Hi,
>
> Apologies if this is a dumb question, I am completely new to programming,
> but I am enjoying what I have learnt so far.
>
> I have several thousand images that are either background or stained images.
> I am trying to write a batch macro that will match the stained image with
> the correct background image. Ultimately, I want to subtract the background
> from the stain.
> I thought this could be done by defining a substring of the file name that
> is shared between the background and stained images, and then opening all
> the images that match with file names that match the substring (which should
> only be two. For example, all the file names follow the same format:
>
>
> [marker name or background(bg)]_[fluorochrome]_[timepoint]_[position].tiff
>
> I have worked out how to define the substring I want, using:
>
> inputFolder=getDirectory("Choose input folder");
> bglist=getFileList(inputFolder);
>
> for (i=0; i<bglist.length; i++) {
> if(startsWith(bglist[i],"bg")) { // I use the background images to define
> the string as they all start with bg.
> str = bglist[i];
> sx = indexOf(str, "_");
> dotx= indexOf(str, ".");
> sub = substring(str, sx, dotx);
>
>
> However, I have no idea how to then open files based on the substring.
> Everything I have tried just returns the first background image. Any help
> would be greatly appreciated!
>
> Many thanks,
> ChrisW
>
>
>
>
> --
> Sent from:
http://imagej.1557.x6.nabble.com/>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>