Median Filter
InterviewTime limit2sMemory limit128 MB
Apply a 3x3 median filter over an image and count filtered pixels whose median value is at least a given threshold.
- Level
Easy3 of 10
- Topics
- Matrix, Sorting, Simulation
- Solved
- No attempts yet
Problem
When nine numbers are sorted, the median is the fifth number.
Image I is a two-dimensional array of pixels with size R × C. Each pixel stores a darkness value V, where 0 ≤ V ≤ 255. Both R and C are between 3 and 40, inclusive.
A 3 × 3 median filter slides over the image starting at the upper-left corner, moving right, then continuing from the next row. At each position, the nine covered pixel values are sorted and the median becomes one pixel of the filtered image J. Therefore, J has size (R - 2) × (C - 2).
Given image I and a threshold T, count how many pixels in J have value greater than or equal to T.
Input
The first line contains R and C. Each of the next R lines contains C pixel values for one row of the image. The last line contains the threshold T.
Output
Print the number of pixels in the filtered image J whose value is greater than or equal to T.