Dialog.create("Threshfinder"); Dialog.addMessage("The following macro will scan all images in the folder of the currently openned image to find threshold for secondary images with '2nd' in the file name. If no image is open, press 'Cancel'."); Dialog.show(); path=getDirectory("image"); list=getFileList(path); close(); for (r = 0; r -1) { open(path+list[r]); dapi = indexOf (currentfilename, "C001"); mpo = indexOf (currentfilename, "C002"); cith3 = indexOf (currentfilename, "C003"); if (dapi == -1 && mpo == -1 && cith3 == -1) { merged = 1; fluo = 0; close(); } else { merged = 0; }; if (dapi > -1) { fluo = 1; close(); } else if (mpo > -1) { fluo = 2; //Put in a tag here - FIND MIN by 50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (fluo == 3) { huemin = 0; huemax = 10; } else if (fluo == 2) { huemin = 75; huemax = 95; }; name = getTitle; origname = replace(name, ".tif", ""); function duplicate() { dup = isOpen(origname+"-1.tif"); if (dup == 1) { selectWindow(origname+"-1.tif"); close(); selectWindow(originame+".tif"); run("Duplicate...", " "); }; if (dup == 0) { selectWindow(origname+".tif"); run("Duplicate...", " "); }; }; type = -1; brimin = 255; for(q = 0; type == -1 && q <= 5; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! if (q == 0) { frun = 0; } else { frun = 1; }; brimin = (brimin - (50*frun)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; minbri = brimin; if (minbri != 255) { //Put in a tag here - FIND MAX by 25~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type != -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin + (25)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; maxbri = brimin; //Put in a tag here - FIND MIN by 10~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type == -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin - (10)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; minbri = brimin; //Put in a tag here - FIND MAX by 5~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type != -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin + (5)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; maxbri = brimin; //Put in a tag here - FIND BRIMIN~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type == -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin - (1)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; minbri = brimin; threshbrimin = minbri + 1; name = getTitle; print(name+"**"+threshbrimin); selectWindow(currentfilename); close(); } else { threshbrimin = minbri; name = getTitle; print(name+"**"+threshbrimin); selectWindow(currentfilename); close(); }; } else if (cith3 > -1) { fluo = 3; //Put in a tag here - FIND MIN by 50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (fluo == 3) { huemin = 0; huemax = 10; } else if (fluo == 2) { huemin = 75; huemax = 95; }; name = getTitle; origname = replace(name, ".tif", ""); function duplicate() { dup = isOpen(origname+"-1.tif"); if (dup == 1) { selectWindow(origname+"-1.tif"); close(); selectWindow(originame+".tif"); run("Duplicate...", " "); }; if (dup == 0) { selectWindow(origname+".tif"); run("Duplicate...", " "); }; }; type = -1; brimin = 255; for(q = 0; type == -1 && q <= 5; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! if (q == 0) { frun = 0; } else { frun = 1; }; brimin = (brimin - (50*frun)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; minbri = brimin; if (minbri != 255) { //Put in a tag here - FIND MAX by 25~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type != -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin + (25)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; maxbri = brimin; //Put in a tag here - FIND MIN by 10~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type == -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin - (10)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; minbri = brimin; //Put in a tag here - FIND MAX by 5~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type != -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin + (5)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; maxbri = brimin; //Put in a tag here - FIND BRIMIN~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for(q = 0; type == -1; q++) { duplicate(); // Color Thresholder 1.50i // Autogenerated macro, single images only! brimin = (brimin - (1)); min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); wait(30); selectWindow(origname+"-1.tif"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=huemin; max[0]=huemax; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=brimin; max[2]=255; filter[2]="pass"; for (w=0;w<3;w++){ selectWindow(""+w); setThreshold(min[w], max[w]); run("Convert to Mask"); if (filter[w]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (e=0;e<3;e++){ selectWindow(""+e); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- name = getTitle; run("Create Selection"); type = selectionType(); close(); }; minbri = brimin; threshbrimin = minbri + 1; name = getTitle; print(name+"**"+threshbrimin); selectWindow(currentfilename); close(); } else { threshbrimin = minbri; name = getTitle; print(name+"**"+threshbrimin); selectWindow(currentfilename); close(); }; }; }; }; };