EP01_11 — 📈 Neighborhood Analysis: 1D Maximum Filter
1.18.14 EP01_11 📈 Neighborhood Analysis: 1D Maximum Filter
In this activity, you must implement a simple morphological maximum filter operating on a one-dimensional signal (vector).
Read an integer n, representing the size of the vector.
Read the n integer elements that make up the original vector v1.
Create a new vector v2, where each position \(i\) is the result of comparing the current element with its immediate neighbors:
\[v2[i] = \max(v1[i-1],\; v1[i],\; v1[i+1])\]
📌 Important:
Boundaries: At the ends of the vector (indices \(0\) and \(n-1\)), the neighborhood has only two elements (the element itself and the only available neighbor). At index \(0\), compare only \(v1[0]\) and \(v1[1]\). At the last index, compare only \(v1[n-2]\) and \(v1[n-1]\).
Output: Print the header “v2:” followed by the values of the resulting vector, one per line.
See an interactive simulator for this question at Figure 1.21 (hover over the results to view the neighborhood window used in the calculation).
1.18.14.1 🧠 Why analyze neighbors?
In image processing, the value of a pixel is rarely isolated; it depends on the context around it. The Maximum Filter is the basis of the Dilation operation in mathematical morphology, serving to:
Function
Visual Effect
Enhancement
Expands bright structures and “thickens” light objects.
Noise Removal
Eliminates small black spots (dark “salt and pepper” noise).
Filling
Closes small holes or gaps in binary shapes.
1.18.14.2 📋 Task (VPL specification)
Input:
An integer n.
On the following lines, the n integer elements of the vector.
Output:
The string v2: on the first line.
On the following lines, each element of v2 (one per line).
1.18.14.3 📌 Examples
Input
Output
Observation
5
10
20
5
30
15
v2:
20
20
30
30
30
At index 1: max(10, 20, 5) = 20
📈 Simulator EP01_11: 1D Local Maximum Filter1x3 Window
Click the elements of v1 (Input) to generate new individual values or hover over the cells of v2 (Output) to inspect the local neighborhood window.
Vector v1 (Input)
⬇️
Vector v2 (Maximum Output)
Hover the mouse cursor over a cell of vector v2 to analyze the local maximum window.
Figure 1.21: EP01_11 Simulator: 1D Local Maximum Filter (1x3 Neighborhood with Border Condition)
# your solution
TestSuite("EP01_11.py").run()
✔️ EP01_11.cases already exists in casos/
📋 7 case(s) loaded from casos/EP01_11.cases
💥 File EP01_11.py not found.