diff --git a/src/normalization.jl b/src/normalization.jl index e16619e7..2996d5ea 100644 --- a/src/normalization.jl +++ b/src/normalization.jl @@ -106,11 +106,50 @@ function imsharpen( image_equalized_gray = Gray.(image_equalized) - image_smoothed = imfilter(image_equalized_gray, Kernel.gaussian(smoothing_param)) + return unsharp_mask(image_equalized_gray, smoothing_param, intensity) +end + +""" + unsharp_mask(image_gray, smoothing_param, intensity, clampmax) + +Apply unsharp masking on (equalized) grayscale ([0, `clampmax`]) image to enhance its sharpness. + +# Arguments +- `image_gray`: The input grayscale image, typically already equalized. +- `smoothing_param::Int`: The pixel radius for Gaussian blurring (typically between 1 and 10). +- `intensity`: The amount of sharpening to apply. Higher values result in more pronounced sharpening. +- `clampmax`: upper limit of intensity values in the returned image.` +# Returns +The sharpened grayscale image with values clipped between 0 and `clapmax`. +""" +function unsharp_mask(image_gray, smoothing_param, intensity, clampmax) + image_smoothed = imfilter(image_gray, Kernel.gaussian(smoothing_param)) + clamp!(image_smoothed, 0.0, clampmax) + image_sharpened = image_gray * (1 + intensity) .- image_smoothed * intensity + clamp!(image_sharpened, 0.0, clampmax) + return round.(Int, image_sharpened) +end + +# For old workflow in final2020.m +""" + (Deprecated) + unsharp_mask(image_gray, smoothing_param, intensity) + +Apply unsharp masking on (equalized) grayscale image to enhance its sharpness. - image_sharpened = - image_equalized_gray .* (1 + intensity) .+ image_smoothed .* (-intensity) - return min.(max.(image_sharpened, 0.0), 1.0) +Does not perform clamping after the smoothing step. Kept for legacy tests of IceFloeTracker.jl. + +# Arguments +- `image_gray`: The input grayscale image, typically already equalized. +- `smoothing_param::Int`: The pixel radius for Gaussian blurring (typically between 1 and 10). +- `intensity`: The amount of sharpening to apply. Higher values result in more pronounced sharpening. +# Returns +The sharpened grayscale image with values clipped between 0 and `clapmax`. +""" +function unsharp_mask(image_gray, smoothing_param, intensity) + image_smoothed = imfilter(image_gray, Kernel.gaussian(smoothing_param)) + image_sharpened = image_gray * (1 + intensity) .- image_smoothed * intensity + return clamp.(image_sharpened, 0.0, 1.0) end """