Open and Close
Time limit1sMemory limit128 MB
Compute the morphological opening and closing of a binary image by a small structuring element for each test case.
- Level
Medium5 of 10
- Topics
- Implementation, Simulation, Matrix
- Solved
- No attempts yet
Problem
Morphological operations extract the image components used to represent and describe region shapes. Two common ones are opening and closing. First we fix how images are represented.
A binary image with rows and columns is the set of coordinates (where and ) at which the pixel equals ; the top-left corner is . A second binary image , called the structuring element, has rows and columns and is represented the same way, except that its top-left pixel is at (so its center is at ).
Two primitive operations are dilation and erosion. The dilation of by is
A (+) B = { a + b | a in A, b in B } ∩ Z
where coordinates are added componentwise and is the set of with and . The erosion of by is
A (-) B = { w | w + b in A for every b in B }
Using these, the opening of by is
A o B = (A (-) B) (+) B
and the closing of by is
A . B = (A (+) B) (-) B
Intuitively, opening removes small details while preserving the overall shape, and closing fills small gaps while preserving the overall shape.
Input
The input consists of several test cases. Each case begins with a line containing three integers , , and separated by spaces (, ). The next lines contain the rows of image , each written as characters that are . (0) or * (1). The following lines describe the structuring element in the same way. The input terminates with a line 0 0 0.
Output
For each case, print the case number on its own line as Case x, followed by a blank line. Then print the opening , followed by a blank line, followed by the closing . Each result image uses the same format as the input images. Separate the output of consecutive cases with a line of exactly 75 equals signs (=); do not print this separator after the last case.