#@File (label = "Choose directory", required=false, style="directory", persist=false, description="Only folders can be specified, not individual images") inputFolder #@String(value="All images in the specified folder need to be of RGB type and of the same size", visibility="MESSAGE") info #@Float (label = "Pixel saturation (%)", value="0.01", min="0.00", max="1.00", style="format:0.00", stepSize="0.01", description="Avoid too much oversaturation. Best stay below 0.10 %") saturation #@File (label = "Save in subfolder", required=false, style="directory", description="If empty, images will not be saved, otherwise end up as .tif images in the specified folder") rgbTargetFolder #@Boolean (label = "Close saved images", value=false, description="Closes the images after processing.") closeImages #@String (label = "Usage", value="This tool applies the maximum possible contrast inside good scientific practice limits
equally to all images in the specified folder.
Keep saturation values between 0.01-0.10. Higher values oversaturate too many pixels!
This is different from normal auto contrast since all images stay optically comparable.
All images which later should be optically compared need to be processed here together in one step!", visibility="MESSAGE") message inputFolder += File.separator; setBatchMode(true); File.openSequence(inputFolder, "scale=100"); originalStack = getTitle(); getDimensions(width, height, channels, slices, frames); labels = newArray(slices); for (i = 1; i <= slices; i++) { Stack.setSlice(i); if (bitDepth() != 24) { exit("Close all non RGB color images"); } labels[i-1] = getInfo("slice.label"); } min = 0; max = 0; absoluteMin = 1e30; absoluteMax = 0; run("HSB Stack"); //setBatchMode("show"); getDimensions(width, height, channels, slices, frames); Stack.setChannel(3); for (s = 1; s <= slices; s++) { Stack.setSlice(s); run("Enhance Contrast...", "saturated=" + saturation); run("Apply LUT", "slice"); } run("RGB Color", "slices"); resultStack = getTitle(); setBatchMode("show"); getDimensions(width, height, channels, slices, frames); for (s = 1; s <= slices; s++) { Stack.setSlice(s); setMetadata("Label", labels[s-1] + "_adj"); } setBatchMode(false); //run("Stack to Images"); if (rgbTargetFolder != 0) { run("Image Sequence... ", "dir=[" + rgbTargetFolder + File.separator + "] format=TIFF name=[] use"); if (closeImages) { close(resultStack); } }