Posted by
Avital Steinberg on
URL: http://imagej.273.s1.nabble.com/Calling-an-ImageJ-macro-on-files-in-sets-of-3-tp5013674p5013683.html
My channel names had a certain pattern, so I needed functions that can
search for a specific pattern in the filename. The functions I used are:
*split(string, delimiters)*
Breaks a string into an array of substrings. *Delimiters* is a string
containing one or more delimiter characters. The default delimiter set "
\t\n\r" (space, tab, newline, return) is used if *delimiters* is an empty
string or split is called with only one argument. Multiple delimiters in
the *string* are merged (taken as one) and delimiters at the start or end
of the *string* are ignored unless the delimiter is a single comma, a
single semicolon or a regular expression. With ImageJ 1.49f or later,
*delimiters* can be also a regular expression enclosed in parentheses, e.g.
*delimiters*="(\n\n)" splits only at empty lines (two newline characters
following each other).
*matches(string, regex)*
Returns *true* if *string* matches the specified regular expression
<
http://en.wikipedia.org/wiki/Regular_expression>. See also: startsWith
<
http://rsb.info.nih.gov/ij/developer/macro/functions.html#startsWith>,
endsWith
<
http://rsb.info.nih.gov/ij/developer/macro/functions.html#endsWith>,
indexOf <
http://rsb.info.nih.gov/ij/developer/macro/functions.html#indexOf>,
replace <
http://rsb.info.nih.gov/ij/developer/macro/functions.html#replace>.
Regular expressions are especially helpful when you're looking for a file
name with a specific pattern. The following site allows you to test your
regular expression and see which strings it would match:
http://regexpal.com/Good luck!
Avital
On Tue, Jul 21, 2015 at 7:37 PM, syntonicC <
[hidden email]> wrote:
> I have a bunch of image files in one folder (TIF). I already wrote a macro
> to
> split the files into RGB channels and then save them to the same directory.
> The output is thus something like this:
>
> -File 1
> -File 1 (red)
> -File 1 (green)
> -File 1 (blue)
> -File 2
> -File 2 (red) ...
> etc.
>
> Next I am using the JACoP plugin which takes two image files and computes
> various kinds of correlation coefficients/analysis between the inputs. For
> each directory, I want to do the following:
>
> Loop through the following for each file in my directory:
> 1. Set input file one to File X (red) and file two to File X (blue)
> 2. Click Analyze
> 3. Set input file one to File X (red) and file two to File X (green)
> 4. Click Analyze
> 5. Set input file one to File x (blue) and file two to File x (green)
> 6. Click Analyze
>
> Then finally:
>
> 7. Save the analysis output log
>
> The problem is that I don't know how to tell ImageJ how to call each of the
> color files in that order. How do I specify that it pulls out the files in
> chunks of three (RGB for image 1), analyses them, and then moves on to the
> next chunk of three (RGB for image 2)?
>
> My approach originally was something like this:
>
> dir=getDirectory("Choose a Directory");
> print(dir);
> list = getFileList(dir);
>
> for (i=0; i<list.length; i++) {
> open(list[i]);
> selectImage(i+1);
> blue = getTitle();
> selectImage(i+2);
> green = getTitle();
> selectImage(i+3);
> red = getTitle();
>
> //Analyze the red, green, and blue images with JACoP plugin
>
> //Move to next set of three images and repeat in next loop through
> }
>
> But this will obviously not work on the second iteration of the loop
> because
> it will need to be i+4, i+5, i+6 etc. There is probably an ImageJ function
> or basic approach to doing this kind of batch analysis but I'm not sure
> what
> to look for. Any suggestions/pseudocode to point me in the right direction
> are appreciated!
>
>
>
>
>
> --
> View this message in context:
>
http://imagej.1557.x6.nabble.com/Calling-an-ImageJ-macro-on-files-in-sets-of-3-tp5013674.html> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html