resetImageJ(); if (roiManager("count") > 0) { roiManager("Delete"); // resetting ROI manager again... seems buggy, leaves old ROIs } // you can't run in batchmode if you're asking the user to select something // they will see nothing when it is time to select //setBatchMode(false); open(); ori = getTitle(); // get image dimensions hgt = getHeight(); wth = getWidth(); print(wth); //Selecting nothing just in case run("Select None"); // set line tool setTool(4); //Line Tool // get user input message= "Line Selection Required\n Please create a break line"; waitForUser(message); getLine(x1, y1, x2, y2, lineWidth); dx = x2-x1; // change in x dy = y2-y1; // change in y if (dx == 0) { // slope is infinity // y intercept is impossible // x is always the same xAty0point = x1; xAtyMaxpoint = x1; } else { // calculate slope and intercept slope = dy / dx; intercept = slope * x1 - y1; // calculate x at y=0 and y=imgheight xAty0point = abs((0-intercept) / slope); // -y = 0 xAtyMaxpoint = ((hgt+intercept) / slope); // -y = hgt } // make polygon to the right of main line makePolygon(xAty0point, 0, xAtyMaxpoint, hgt, wth, hgt, wth, 0); // add to manager and its inverse roiManager("Add"); run("Make Inverse"); roiManager("Add"); run("Make Inverse"); // ROI[0] should be right side of line // ROI[1] should be left side run("Select None"); // duplicate image run("Duplicate...", "title=Right"); // fill in left side of line with blue and segment on right side roiManager("Select", 1); setForegroundColor(0, 0, 255); run("Fill", "slice"); run("Select None"); // find "black" pixels selectWindow("Right"); findblackpixels(); run("Create Selection"); roiManager("Add"); selectWindow("Right"); run("Close"); // fill in right side and focus on left selectWindow(ori); run("Duplicate...", "title=Left"); roiManager("Select", 0); setForegroundColor(0, 0, 255); run("Fill", "slice"); run("Select None"); // find "black" pixels findblackpixels(); run("Create Selection"); roiManager("Add"); selectWindow("Left"); run("Close"); // get measurements selectWindow(ori); run("Select None"); roiManager("Select", 2); // Right side run("Measure"); run("Select None"); roiManager("Select", 3); // Left side run("Measure"); run("Select None"); /////////////////////////////////////// function resetImageJ() { run("Options...", "iterations=1 count=1 edm=Overwrite"); run("Line Width...", "line=1"); run("Colors...", "foreground=black background=white selection=yellow"); run("Clear Results"); run("Close All"); print("\\Clear"); run("ROI Manager..."); run("Input/Output...", "jpeg=75 gif=-1 file=.csv use_file copy_row save_column save_row"); run("Set Measurements...", "area mean standard modal min centroid center perimeter bounding fit shape feret's integrated median skewness kurtosis area_fraction stack redirect=None decimal=3"); } /////////////////////////////////////// /////////////////////////////////////// function findblackpixels() { // Color Thresholder 1.48v // 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]=0; max[0]=75; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=0; max[2]=150; 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------------- } /////////////////////////////////////// -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html