// At the moment the macro does not check if the largest possible circle is used. // If the ring is not more or less centred a smalller ROI could be measured. answer = 1; title = getTitle(); title1 = File.nameWithoutExtension(); run("Duplicate...", " "); run("Split Channels"); selectWindow(title1+"-1.JPG (blue)"); close(); selectWindow(title1+"-1.JPG (red)"); close(); // Threshold and clean up to find ring selectWindow(title1+"-1.JPG (green)"); setAutoThreshold("Intermodes dark"); setOption("BlackBackground", false); run("Convert to Mask"); run("Despeckle"); run("Remove Outliers...", "radius=5 threshold=50 which=Bright"); run("Erode"); run("Dilate"); run("Dilate"); run("Erode"); run("Erode"); run("Despeckle"); // Make circle and find ring edge a=1080; b=255; c=2874; d=2874; makeOval(a, b, c, d); best = 0; for (i=1; i<25; i++){ run("Make Band...", "band=25"); getStatistics(area, mean, min, max, std, histogram); if ((max==255)&&(std>100)&&(std > best)){ i = 25; a = a-25; c = c+50; b = b-25; d = d+50; }else{ best = std; a = a-25; c = c+50; b = b-25; d = d+50; makeOval(a, b, c, d); } } // Now the ROI should move to check if it should grow further // Not implemented. // Move ROI to check for better overlap with threshold ring while (answer==1){ makeOval(a, b, c, d); roiManager("Add"); run("Make Band...", "band=25"); getHistogram(values, counts, 256); p0=(counts[255]); a = a+25; makeOval(a, b, c, d); run("Make Band...", "band=25"); getHistogram(values, counts, 256); p1=(counts[255]); roiManager("Add"); a = a-50; makeOval(a, b, c, d); run("Make Band...", "band=25"); getHistogram(values, counts, 256); p2=(counts[255]); roiManager("Add"); a = a+25; b = b+25; makeOval(a, b, c, d); run("Make Band...", "band=25"); getHistogram(values, counts, 256); p3=(counts[255]); roiManager("Add"); b = b-50; makeOval(a, b, c, d); run("Make Band...", "band=5"); getHistogram(values, counts, 256); p4 = (counts[255]); roiManager("Add"); b = b+25; // ROI back to middle position // check for best circle overlap. if ((p0>p1)&&(p0>p2)&&(p0>p3)&&(p0>p4)) answer = 0; if ((p1>p0)&&(p1>p2)&&(p1>p3)&&(p1>p4)) {a = a+25; p0 = p1;} if ((p2>p0)&&(p2>p1)&&(p2>p3)&&(p2>p4)) {a = a-25; P0 = p2;} if ((p3>p0)&&(p3>p1)&&(p3>p2)&&(p3>p4)) {b = b+25; p0 = p3;} if ((p4>p0)&&(p4>p1)&&(p4>p2)&&(p4>p3)) {b = b-25; p0 = p4;} } roiManager("select", (roiManager("count")-5)); setBackgroundColor(255, 255, 255); run("Clear Outside"); setForegroundColor(0, 0, 0); run("Fill"); run("Analyze Particles...", "size=4-Infinity summarize add"); selectWindow(title); roiManager("select", (roiManager("count"))-1); setBackgroundColor(255, 255, 255); run("Clear Outside"); run("Color Threshold..."); // Color Thresholder 2.0.0-rc-30/1.49t // 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]=46; max[0]=144; filter[0]="pass"; min[1]=32; max[1]=255; filter[1]="pass"; min[2]=0; max[2]=255; 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------------- roiManager("Delete"); run("Analyze Particles...", "size=4-Infinity summarize add"); -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html