PIXELBANKv9.1.0
Menu

Image Sharpening with Unsharp Mask

Given a 2D image, sigma, and an amount parameter, apply unsharp mask sharpening:

  1. Generate a Gaussian kernel with kernel_size = 3
  2. Blur the image using valid convolution
  3. For each pixel in the valid region: sharpened=original+amount×(original−blurred)\text{sharpened} = \text{original} + \text{amount} \times (\text{original} - \text{blurred})

The original pixel at position (i,j)(i, j) in the blurred output corresponds to pixel (i+1,j+1)(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:

Input:
image = [[10, 10, 10], [10, 10, 10], [10, 10, 10]]
sigma = 1.0, amount = 1.0
Output:
[[10.0]]
Reasoning:
  • The given image is 3×33 \times 3, but since the kernel size is 33, the valid region for convolution is 1×11 \times 1, resulting in a blurred image of size 1×11 \times 1.
  • The Gaussian kernel with σ=1.0\sigma = 1.0 is generated, but since the image is uniform (1010 everywhere), the blurred pixel will also be 1010.
  • 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\text{sharpened} = \text{original} + \text{amount} \times (\text{original} - \text{blurred}) = 10 + 1.0 \times (10 - 10) = 10.
  • The final sharpened image, rounded to 44 decimal places, is [[10.0]][[10.0]], but since the problem asks for a 1×11 \times 1 output and the input image is 3×33 \times 3, only the center pixel is considered, resulting in [10.0][10.0] being the only value, thus the output is [[10.0]][[10.0]] which can be simplified to [10.0][10.0] in a 1×11 \times 1 matrix, so the output is [[10.0]][[10.0]] which in this context is equivalent to [10.0][10.0] but following the exact format of the question the answer should be in a 1×11 \times 1 matrix format: [[10.0]][[10.0]] is the same as saying the output is [10.0][10.0] in a 1×11 \times 1 matrix, hence the answer is [[10.0]][[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
🔒

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.

solution.py

Test Results

0/0
Run code to see test results.