eolymp
bolt
Try our new interface for solving problems
Məsələlər

Contour Tracing

Contour Tracing

In computer vision, objects of interest are often represented as regions of \textbf{1}'s in a binary image (bitmap). An important task in the identification of objects is to trace the contour (also called border and boundary) in an object. We assume that the bitmap does not contain any \textbf{1}'s on the borders. To trace the contour of a single object, we can use a procedure known as the Moore boundary tracking algorithm as follows: \begin{enumerate} \item Scan from the top row to the bottom row, from left to right in each row, until an object pixel is found. Call this object pixel \textbf{b0}, and its west background neighbour \textbf{c0}. \item Examine the \textbf{8} neighbours of \textbf{b0}, starting at \textbf{c0} and proceeding in clockwise direction. Let \textbf{b1} denote the first neighbour object pixel encountered, and \textbf{c1} be the background neighbour immediately preceeding \textbf{b1}. Store the locations of \textbf{b0} and \textbf{b1}, and append \textbf{b0} and \textbf{b1} to the contour. \item Let \textbf{b = b1} and \textbf{c = c1} \item Let the \textbf{8} neighbours of \textbf{b}, starting at \textbf{c} and proceeding in a clockwise direction, be denoted as \textbf{n1}, \textbf{n2}, ..., \textbf{n8}. Find the first object neighbour nk in this sequence. \item Let \textbf{b = nk}, \textbf{c = n(k-1)}. Append b to the contour. \item Repeat steps \textbf{4} and \textbf{5} until \textbf{b = b0} and the next contour point found is \textbf{b1}. The last two points \textbf{b0} and \textbf{b1} are repeated and should not be appended to the contour again. \end{enumerate} The first steps of the algorithm is illustrated in the figure below (only the pixels on the boundary are labelled \textbf{1} in this bitmap): \includegraphics{https://static.e-olymp.com/content/11/110a5e74055e31bb2ff60f04a6412d49d6501d06.jpg} In this problem, you will be given a bitmap with at most \textbf{200} rows and \textbf{200} columns. The bitmap contains a number of objects. You are to determine the length of the contour for each object in the bitmap using the procedure above. In the bitmap, a pixel intensity of \textbf{0} represents the background, and a pixel intensity of \textbf{1} represents an object pixel. Two pixels with intensity \textbf{1} belong to the same object if there is a path from one pixel to another consisting of only \textbf{1}'s, and the path is allowed to follow in any of the 8 compass directions. The borders of the bitmap (first row, last row, first column, last column) contain only background pixels. Any object consisting of fewer than \textbf{5} pixels should be ignored as it is most likely noise. None of the objects in the bitmap has holes. Equivalently, there exists a path of background pixels following only the \textbf{4} main compass directions (\textbf{N}, \textbf{S}, \textbf{E}, \textbf{W}) for every pair of background pixels in the bitmap. \InputFile The input consists of a number of cases. Each case starts with two positive integers on a line, indicating the number of rows (\textbf{R}) and the number of columns (\textbf{C}) in the bitmap. The bitmap is given in the following \textbf{R} lines each containing a string of \textbf{0}'s and \textbf{1}'s of length \textbf{C}. The input is terminated by a case starting with \textbf{R = C = 0}. The last case should not be processed. \OutputFile For each case, print the case number on its own line. In the next line, print the lengths of the contours of all objects found in the bitmap, sorted in ascending order. Separate the contour lengths by a single space on that line. If the bitmap has no object that have at least \textbf{5} pixels, output the line '\textbf{no objects found}' instead.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
7 7
0000000
0011110
0111100
0011100
0111100
0111100
0000000
16 7
0000000
0011110
0111100
0011100
0111100
0111100
0000000
0011000
0100110
0000000
0001000
0010100
0010000
0111000
0111000
0000000
4 4
0000
0000
0010
0000
0 0
Çıxış verilənləri #1
Case 1
14
Case 2
8 12 14
Case 3
no objects found
Mənbə 2011 Rocky Mountain Regional ACM Contest Information