Image Sharpening with Unsharp Mask
Given a 2D image, sigma, and an amount parameter, apply unsharp mask sharpening:
- Generate a Gaussian kernel with kernel_size = 3
- Blur the image using valid convolution
- For each pixel in the valid region: sharpened=original+amount×(original−blurred)
The original pixel at position (i,j) in the blurred output corresponds to pixel (i+1,j+1) in the original image (since kernel_size=3, offset is 1).
Return the sharpened image rounded to 4 decimal places.
Example:
image = [[10, 10, 10], [10, 10, 10], [10, 10, 10]] sigma = 1.0, amount = 1.0
[[10.0]]
- The given image is 3×3, but since the kernel size is 3, the valid region for convolution is 1×1, resulting in a blurred image of size 1×1.
- The Gaussian kernel with σ=1.0 is generated, but since the image is uniform (10 everywhere), the blurred pixel will also be 10.
- For the single pixel in the valid region, the sharpened value is calculated as: sharpened=original+amount×(original−blurred)=10+1.0×(10−10)=10.
- The final sharpened image, rounded to 4 decimal places, is [[10.0]], but since the problem asks for a 1×1 output and the input image is 3×3, only the center pixel is considered, resulting in [10.0] being the only value, thus the output is [[10.0]] which can be simplified to [10.0] in a 1×1 matrix, so the output is [[10.0]] which in this context is equivalent to [10.0] but following the exact format of the question the answer should be in a 1×1 matrix format: [[10.0]] is the same as saying the output is [10.0] in a 1×1 matrix, hence the answer is [[10.0]].
Constraints:
- image is a 2D list (at least 3x3)
- sigma is a positive float
- amount is a non-negative float
- kernel_size is fixed at 3
- Return 2D list of sharpened values rounded to 4 decimal places
Background Knowledge
The problem involves applying unsharp mask sharpening to an image, which is a technique used to enhance the details and textures of an image. This is achieved by amplifying the high-frequency components of the image. The key concept here is the use of a Gaussian kernel for blurring the image. A Gaussian kernel is a 2D array of values that follows a Gaussian distribution, where the center of the kernel has the highest value and the values decrease as you move away from the center. The Gaussian kernel is used for blurring because it gives more weight to the neighboring pixels that are closer to the center pixel, resulting in a smoother image.
The unsharp mask sharpening technique works by subtracting the blurred image from the original image, which highlights the high-frequency components. The amount of sharpening is controlled by the amount parameter, which determines how much of the high-frequency components are added back to the original image. The resulting sharpened image has more defined edges and textures. The formula for sharpening each pixel is given by: sharpened=\text{original}+\text{amount}×(\text{original}−\text{blurred}). This formula shows that the sharpened pixel value is a combination of the original pixel value and the difference between the original and blurred pixel values, scaled by the amount parameter.
The problem also mentions valid convolution, which means that the kernel is only applied to the pixels where the entire kernel can fit within the image boundaries. This results in a smaller output image, where each pixel corresponds to the center pixel of the kernel. In this case, since the kernel size is 3, the output image will be 2 pixels smaller in both width and height, and the pixel at position (i,j) in the blurred output corresponds to the pixel at position (i+1,j+1) in the original image.
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.