@@ -55,6 +56,7 @@ doScalingDuringRegistration = false; // When registering ROIs between different
defaultFiducialPlacementOption = 1; // 0 if the fiducials are placed along the gap. 1 if they are placed to the sides of it.
defaultGapOrientationOption = 0; // 0 if the gap is vertical. 1 if the gap is horizontal. 2 if the gap orientation is unknown or varies from series to series.
fiducialBlurFactor = 1/46; // The higher fiducialBlurFactor is, the more blurred the fiducial detection image will be. (Gaussian blur sigma will be equal to image width * fiducialBlurFactor.)
defaultContrastEnhancementPercentage = 20;
selectionColor = "red";
@@ -69,6 +71,8 @@ leewayFractionToUse = 0.9; // How far should we actually expand the rectangle?
roiManagerWindowPadding = 10; // Padding between the ROI Manager window and the edge of the screen (pixels).
roiManagerWindowWidth = 500; // Width of the ROI Manager window (pixels).
roiManagerWindowHeight = 600; // Height of the ROI Manager window (pixels).
logWindowPaddding = 100; // Padding between the Log window and the edge of the screen (pixels).
resultsWindowPaddding = 200; // Padding between the Results window and the edge of the screen (pixels).
intermediateDebugImagePrefix = "__";
intermediateSignificantImagePrefix = "_";
@@ -76,6 +80,9 @@ summaryTitle = "Summary";
fiducialPlacementOptions = newArray("along the gap", "across the gap");
Table.renameColumn("Area", "Area (" + unit + "^2)");
@@ -578,6 +604,20 @@ function findFiducials(imageIndex) {
}
setSelectionName(getImageNameForStage(imageIndex, "rgb_input") + " Line Across Gap");
roiManager("Add");
// "(Thick) horizontal line" selection marking the area between the fiducials. Will not correspont to the "rotated rectangle" selection directly, but may allow for better gap threshold finding.
run("Enhance Contrast...", "saturated=20 normalize"); // High values of "saturated" (up to 20 was tested) seem to help with low-contrast images.
run("Enhance Contrast...", "saturated=" + contrastEnhancementPercentage +" normalize"); // High values of "saturated" (up to 20 was tested) seem to help with low-contrast images.
run("Median...", "radius=5"); // TODO: Median radius should be smaller than the cell size. (About one third of the SE size used for morphological gradient/opening seems to work.)
}
@@ -753,27 +790,33 @@ function findEmptyRegionsInAllImages(emptyRegionThreshold) {
function determineEmptyRegionThreshold() {
thresholds = newArray();
print("\nFinding empty region threshold in the first image, \"" + getImageNameForStage(0, "rgb_input") + "\".");
getThreshold(lowerRectangleThreshold, upperRectangleThreshold); // Anything that is <= upperRectangleThreshold will be considered to be the gap.
print("Threshold calculated using \"" + thresholdingMethodToUse + "\" method from all pixels of \"" + getImageNameForStage(0, "rgb_input") + " Rectangle Between Fiducials\": " + upperRectangleThreshold);
print("Threshold calculated using \"" + thresholdingMethodToUse + "\" method from all pixels of \"" + getImageNameForStage(0, "rgb_input") + " Rectangle Between Fiducials\": " + upperRectangleThreshold);
// Find the threshold across the gap (along the "thick line" crossing the gap).
// Careful: if the line is at an angle other than 90°, the threshold may be too high,
// because it may happen that none of the columns align with the gap, and so each one's
// intensity is higher than the intensity of the actual empty background.
print("Threshold calculated using \"" + thresholdingMethodToUse + "\" method from plot along \"" + getImageNameForStage(0, "rgb_input") + " Line Across Gap\": " + upperLineThreshold);
result = Math.min(upperLineThreshold, upperRectangleThreshold);
print("Returning threshold = min(" + upperLineThreshold + ", " + upperRectangleThreshold + ") = " + result); // This is only a redundant debugging output.
// TODO: BUG: Sometimes , an error may occur because no linear selection is active when calling run("Plot Profile"). It is unclear when this can happen (seems almost non-deterministic). This has been so far only observed when the horizontal line threshold computation was enabled.
//showMessage("a");
/**/
// Find the threshold across the gap, perfectly horizontally (along the "thick line" crossing the gap horizontally).
// Create a small image containing the plot's values, so that it can be thresholded with one of the built-in thresholding functions.
plotImageHeight = 1; // A height greater than 1 wuld be used mostly for debugging/viewing purposes. For most of the thresholding methods, the height of 1 should be enough.
getThreshold(lowerHorizontalLineThreshold, upperHorizontalLineThreshold); // Anything that is <= upperHorizontalLineThreshold will be considered to be the gap.
print("Threshold calculated using \"" + thresholdingMethodToUse + "\" method from plot along \"" + getImageNameForStage(0, "rgb_input") + " Horizontal Line Across Gap\": " + upperHorizontalLineThreshold);