I am attempting to write a macro that will act as a particle counter (I am counting trichomes on plant leaves). My experience with ImageJ programming is pretty limited. I want the macro to count particles on all of the images in a folder. It seems that my macro is not even getting to the point where it is executing the particle analysis. When I run the macro I get this error message:
')' expected in line 4. <list> = getFileList(dir); Here is the code that I have written (up until the commands for the actual particle analysis): macro "Particle Count" { dir = getDirectory("C:\Users\Matt\Desktop\Matt\"); list = getFileList(dir); if (getVersion>="1.40e") setOption("display labels", true); setBatchMode(true); for (i=0; i<list.length; i++) { path = dir+list[i]; showProgress(i, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) Any suggestions? Thanks, Matt |
Hi Matt,
the culprit is the String with the directory. In String literals (Strings with quotes), the backslash is used for inserting special characters. If you want to have a backslash in a String, you have to type two backslashes: \\ In "C:\Users\Matt\Desktop\Matt\" the last Backslash is interpreted as "The following character should be taken as a special character of the String: Put a quote character into the String" So, the closing parenthesis and the semicolon are still part of the String, and not interpreted as program text. You need: dir = getDirectory("C:\\Users\\Matt\\Desktop\\Matt\\"); Michael ________________________________________________________________ On 24 Feb 2010, at 15:21, Matt TLAB wrote: > I am attempting to write a macro that will act as a particle > counter (I am > counting trichomes on plant leaves). My experience with ImageJ > programming > is pretty limited. I want the macro to count particles on all of > the images > in a folder. It seems that my macro is not even getting to the > point where > it is executing the particle analysis. When I run the macro I get > this > error message: > ')' expected in line 4. > <list> = getFileList(dir); > > Here is the code that I have written (up until the commands for the > actual > particle analysis): > macro "Particle Count" { > dir = getDirectory("C:\Users\Matt\Desktop\Matt\"); > list = getFileList(dir); > if (getVersion>="1.40e") > setOption("display labels", true); > setBatchMode(true); > for (i=0; i<list.length; i++) { > path = dir+list[i]; > showProgress(i, list.length); > if (!endsWith(path,"/")) open(path); > if (nImages>=1) > > > Any suggestions? > > Thanks, > Matt > -- > View this message in context: http://n2.nabble.com/getFileList- > Issue-tp4626046p4626046.html > Sent from the ImageJ mailing list archive at Nabble.com. |
Michael,
Thanks! That fixed that problem. I am now prompted to select the folder when I run the macro. The folder I am using right now is a test folder. It has 5 images in it. When prompted by the macro, I select the folder and it runs the program on the first image in the folder. It looks like my code is correct, because the output is exactly what I want it to be (a particle count). However, after processing the first image in the folder, I get a message that says: There are no images open. The program is not moving on to the next image in the folder. Here is the full text of the macro I wrote. macro "Particle Count" { dir = getDirectory("C:\\Users\\Matt\\Desktop\\Matt\\"); list = getFileList(dir); if (getVersion>="1.40e") setOption("display labels", true); setBatchMode(true); for (i=0; i<list.length; i++) { path = dir+list[i]; showProgress(i, list.length); if (!endsWith(path,"/")) open(path); if (nImages>=1) {run("8-bit"); setAutoThreshold(); //run("Threshold..."); setThreshold(128, 255); run("Threshold", "thresholded remaining black"); setAutoThreshold(); run("Analyze Particles...", "minimum=1 maximum=999999 bins=20 show=Nothing display summarize record size"); close(); close();} } } Do I need to add something to get the macro to move through all of the images in the folder? I thought that the first part of the macro specified this. Thanks, Matt |
Hi Matt,
why do you run close() twice? I expect that only one image gets opened - 'Analyze Particles' won't create an image with 'show=Nothing'. I also wonder about the initial two thresholding commands, they don't do any harm, but only the second one will be used for Analyze Particles. Michael ________________________________________________________________ On 24 Feb 2010, at 16:59, Matt TLAB wrote: > Michael, > Thanks! That fixed that problem. I am now prompted to select the > folder > when I run the macro. The folder I am using right now is a test > folder. It > has 5 images in it. When prompted by the macro, I select the > folder and it > runs the program on the first image in the folder. It looks like > my code is > correct, because the output is exactly what I want it to be (a > particle > count). However, after processing the first image in the folder, I > get a > message that says: > There are no images open. > > The program is not moving on to the next image in the folder. Here > is the > full text of the macro I wrote. > > macro "Particle Count" { > dir = getDirectory("C:\\Users\\Matt\\Desktop\\Matt\\"); > list = getFileList(dir); > if (getVersion>="1.40e") > setOption("display labels", true); > setBatchMode(true); > for (i=0; i<list.length; i++) { > path = dir+list[i]; > showProgress(i, list.length); > if (!endsWith(path,"/")) open(path); > if (nImages>=1) {run("8-bit"); > setAutoThreshold(); > //run("Threshold..."); > setThreshold(128, 255); > run("Threshold", "thresholded remaining black"); > setAutoThreshold(); > run("Analyze Particles...", "minimum=1 maximum=999999 bins=20 > show=Nothing > display summarize record size"); > close(); > close();} > } > } > > > Do I need to add something to get the macro to move through all of the > images in the folder? I thought that the first part of the macro > specified > this. > > Thanks, > Matt > -- > View this message in context: http://n2.nabble.com/getFileList- > Issue-tp4626046p4626658.html > Sent from the ImageJ mailing list archive at Nabble.com. |
Free forum by Nabble | Edit this page |