Hello all,
I've been putting together a macro to threshold an image, analyse particles at four points and then save the summary. This, eventually, worked on its own so I have attempted to adapt the macro so that it will automatically do the same for all images in the directory. The image set I am testing on are jpeg files named from 19 through to 36. I am able to cycle through the directory and have all of the images open, wait for 2 seconds and close again before moving on to the next image with a similar, simpler bit of code. However, when I try to run the macro below the first image (19.jpeg) will open and be processed and then any of 22, 23 or 25 will open and be processed REPEATEDLY, in a loop. Any ideas? I've been considering if it's a conflict caused by the .xls summary files being saved in the same directory. Macro: dir=getDirectory("image"); close(); list=getFileList(dir); for (i=0;i<list.length;i++){ path = dir+list[i]; showProgress(i, list.length); if (!endsWith(path,"/")) open(path); name=getTitle(); run("Set Scale...", "distance=432 known=15 pixel=1 unit=mm"); // Color Thresholder 1.47v // Autogenerated macro, single images only! min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=80; max[0]=215; filter[0]="stop"; min[1]=20; max[1]=255; filter[1]="pass"; min[2]=0; max[2]=136; filter[2]="pass"; for (i=0;i<3;i++){ selectWindow(""+i); setThreshold(min[i], max[i]); run("Convert to Mask"); if (filter[i]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (i=0;i<3;i++){ selectWindow(""+i); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- makeRectangle(172, 1676, 284, 232); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing exclude clear summarize"); makeRectangle(772, 1676, 284, 232); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing exclude clear summarize"); makeRectangle(1336, 1676, 284, 232); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing exclude clear summarize"); makeRectangle(1880, 1676, 284, 232); run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing exclude clear summarize"); selectWindow("Summary"); index = lastIndexOf(name, "."); if (index!=-1) name = substring(name, 0, index); name2 = name + ".xls"; saveAs("Text", dir+name2); selectWindow("Summary"); run("Close"); selectWindow(a); run("Close"); }</i> |
UPDATE
I managed to get it to do what I wanted my containing the Thresholding analysing and summary saving parts in one macro, and then making another macro that will run this macro on repeat for the files in the directory. I would still be interested to know where the conflict came from, although I suspect it comes from the constant redefining of names and directories of the auto Colour Thresholding technique clashing with the repeat part of the macro needing consistency. |
This post was updated on .
In reply to this post by Matt Boyle
Hello, my name is Patricio.
I have the same problem can you help. As you fixed paste you code macros please Sorry my English is bad. thanks Best wishes |
Free forum by Nabble | Edit this page |