run("Colors...", "foreground=white background=black selection=yellow"); run("Options...", "iterations=1 black count=1"); // // All image calculation using logical operators take zero values as zero and 255 as "one" in the case below // So inverted luts only change black to white and white to black but zero stays zero meaning black was zero and after // inverting the LUT white is now zero. // Anything measured needs to have value 255 // So 255 or '1' is the object // Required ImageJ version requires("1.43u"); // requires threshold colour RGBtoLAB AssessFibrosis(); function AssessFibrosis() { exclude_high_th=72; lumen_low_th=240; fibrosis_high_th=130; name= getTitle image_name = File.name; OriginalImage = getImageID(); run("Duplicate...", "title=total_area"); // Obtain total area TotalArea = getImageID(); selectImage(TotalArea); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("RGB Stack"); run("Convert Stack to Images"); selectWindow("Red"); rename("0"); selectWindow("Green"); rename("1"); selectWindow("Blue"); rename("2"); min[0]=0; max[0]=250; filter[0]="pass"; min[1]=0; max[1]=250; filter[1]="pass"; min[2]=0; max[2]=250; filter[2]="pass"; for (i=0;i<3;i++){ selectWindow(""+i); setThreshold(min[i], max[i]); run("Make Binary", "thresholded remaining"); 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------------ run("8-bit"); //Now obtain fibrosis component selectImage(OriginalImage); run("Duplicate...", "title=fibrosis_area"); FibrosisImage = getImageID(); selectImage(FibrosisImage); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("RGBtoLab "); run("RGB Stack"); run("Convert Stack to Images"); selectWindow("Red"); rename("0"); selectWindow("Green"); rename("1"); selectWindow("Blue"); rename("2"); min[0]=0; max[0]=lumen_low_th-1; filter[0]="pass"; min[1]=fibrosis_high_th; 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("Make Binary", "thresholded remaining"); 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------------ run("8-bit"); run("Set Measurements...", "area limit redirect=None decimal=3"); selectImage("total_area"); // We need the size of the exclusion part totarea=0; run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing clear"); for (i=0; iSave As> selectWindow("fibrosis_area"); saveAs("Tiff..."); // File>Save As.\> selectWindow("total_area"); saveAs("Tif...") // File>Save As.\> }// End of macro