Description: Implement an image filter using a convolution operation. The filter will be applied to an input image to produce a filtered output image.
Constraints:
Examples:
[ [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1] ][ [0, -1, 0], [-1, 5, -1], [0, -1, 0] ][ [0, 0, 0, 0, 0], [0, 6, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0] ]Hints:
Solution: `python def apply_filter(image, filter): rows, cols = len(image), len(image[0]) filter_size = len(filter) half_filter_size = filter_size // 2
output = [[0] * cols for _ in range(rows)]
for i in range(half_filter_size, rows - half_filter_size):
for j in range(half_filter_size, cols - half_filter_size):
pixel_sum = 0
for m in range(filter_size):
for n in range(filter_size):
pixel_sum += image[i + m - half_filter_size][j + n - half_filter_size] * filter[m][n]
output[i][j] = pixel_sum
return output
`
Note: The above solution assumes that the input image and filter are valid and that the filter size is odd.
DarkInterview URL: The provided DarkInterview URL does not yield any additional information beyond the question ID.
Reddit (r/cscareerquestions, r/leetcode, r/csMajors): No relevant threads or discussions found.
1point3acres: No relevant threads or discussions found.
PracHub: No relevant practice problems found.
Glassdoor: No relevant interview questions found.
Blind: No relevant discussions found.
GitHub: No relevant repositories or code snippets found.
Interview Prep Sites: No relevant interview questions found.
Note: Despite extensive searching, no additional information or variations of the problem were found. The problem statement, constraints, examples, hints, and solution provided above are based on the information available from the DarkInterview URL and general knowledge of image filtering techniques.