[Noi Guide 2011] Structural features of images

Source: Internet
Author: User

Problem Description

In the image alignment, one method is to use the edge information in the image to calculate the representative structural feature of each edge information as a criterion for the similarity of the two images. The Water-filling method is to start at one end of each edge graph, walking around the connected edge points and numbering them sequentially. If you go to a step and encounter more than one of the different connection points, you will be divided into different paths and continue walking until there are no connection points. If a point and another point are next to the left and right, it is called a connection.

For example, the image in Figure 1 contains three edge graphs, each of which consists of a number of interconnected edge points. The black squares represent the edge points, and the white squares represent the background. In the Water-filling method, first, starting from the first column (row), from left to right, top to bottom, the first black dot is first found and numbered 1. Then, find the next numbered 1 connection point and number 2. Follow this method to proceed to the next point and sequentially number. There are two numbered connection points after the point numbered 6, at which point they are divided into two routes and numbered 7 at the same time to continue to go down. When you go to the point where there is no connection, end the numbering of the existing edge graph, and continue numbering the other edge graphs in the image. Walk through Figure 1 all the edge graphs and get the number 2 shown. Therefore, the steps required to walk through the three fringe graphs are 12, 7 and 3 respectively; Therefore, 12, 7 and 3 can be used as structural features representing this image. Please note: Two points on the diagonal are not counted as connections, such as:

Please write a program to calculate each image, after the Water-filling method to walk through all of the edge graph, the number of steps to walk each edge graph according to the order of visits listed.

Enter a description

The input file contains a square image. Each group of images begins with the width N of the graph (l≤n≤1000). The next n rows represent the contents of the image: 0 indicates the white point of the background, and 1 indicates the black edge.

Output Description

For each input image, after all the edge graphs are water-filling, the image is printed with a few fringe graphs. Next, the number of steps to be taken for each edge graph is ascending.

Sample Input

10

0000000000

0011110000

0000010000

0011111000

0010110100

0010010110

0011110010

0100010010

0100000110

0100000000

Sample output

3

3

7

12

Ideas

It is a typical good question for practicing wide search. You can understand the principle of wide search through it, understand the deep search in the difference between wide search.

Record how many times a wide search to the queue, record how many times the team.

The output is queued in descending order.

typess=RecordX,y,z:longint; End;ConstConArray[1..2,1..4] ofLongint= ((1,-1,0,0),(0,0,-1,1));varA:Array[0..1010,0..1010] ofLongint; F:Array[0..1000000] ofSS; B:Array[0..1000000] ofLongint; N,i,sum,j:longint;procedureInit;varCh:char;beginFillchar (A,sizeof (a),0);    READLN (n);  fori:=1  toN Do        begin             forj:=1  toN Do                beginread (CH); ifCh='1'  Thena[i,j]:=1; End;        READLN; End;End;proceduresort (l,r:longint);varI,j,x,y:longint;beginI:=l;j:=r;x:=b[(L+r)Div 2]; Repeat         whileB[i]<x DoInc (I);  whileB[j]>x DoDec (j); ifI<=j Then            beginy:=B[i]; B[i]:=B[j]; B[J]:=y;                Inc (I);            Dec (j); End; untilI>J; ifL<j Thensort (l,j); ifI<r Thensort (i,r);End;procedureBFS (x,y:longint);varI,xx,yy,head,tail:longint;beginHead:=0; tail:=1; f[1].x:=x;f[1].y:=y;f[1].z:=1; A[x,y]:=0;  whileHead<tail Do        beginInc (head);  fori:=1  to 4  Do                beginXX:=f[head].x+con[1, I]; YY:=f[head].y+con[2, I]; ifa[xx,yy]=1  Then                        beginInc (tail); f[tail].x:=xx; F[TAIL].Y:=yy; F[TAIL].Z:=f[head].z+1; A[XX,YY]:=0; End; End; End;    Inc (SUM); B[sum]:=f[head].z;End;beginassign (input,'graph.in'); Assign (output,'Graph.out');    Reset (input);    Rewrite (output);    Init  fori:=1  toN Do         forj:=1  toN Do            ifa[j,i]=1  ThenBFS (j,i); Sort (1, sum);    Writeln (sum);  fori:=1  toSum DoWriteln (B[i]);    Close (input); Close (output); End.
View Code

[Noi Guide 2011] Structural features of images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.