Skip to content

Commit

Permalink
Merge pull request #432 from WilhelmusLab/431-create-dedicated-unshar…
Browse files Browse the repository at this point in the history
…p_mask-function

feat: unsharp mask
  • Loading branch information
cpaniaguam authored Oct 4, 2024
2 parents 9381c69 + 5e0c28b commit e84ce83
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/normalization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down

0 comments on commit e84ce83

Please sign in to comment.