A solution [not particularly perfect] for a small map in the big picture

Source: Internet
Author: User
Tags transparent color

A few days ago in the forum sent the following article, "Big picture inside looking for small figure ah look for small figure ~~~~~[help thinking", the purpose is to find out a large map of a small picture of the number and location information. Maybe there is no good way to do it, and in the end I will use a less efficient way to solve the problem.

The main ideas are:

1, the large map of the RGB value of each pixel into a matrix. So we're going to get such a matrix A

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000001111111111111111100000000001111111111111111100000000001111111111111111100000000001111111111111111100000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Each number represents a point. 1 for this is the pixel point of the graph we want to find, and 0 for this is the background pixel point

2, small graph also read into a matrix, we get matrix B

11111111111111111
11111111111111111
11111111111111111
11111111111111111
11111111111111111

3. Take out the first line of the B1 matrix B, and the first line of the large graph matrix a A1. The B1 is then passed into the KMP algorithm as the pattern parameter.

For example:

KMP (A1,B1) =-1, PASS

KMP (A2,B1) =-1, PASS

KMP (A3,B1) =5 so we can see where the first occurrence of the small figure in the larger image is (x=5,y=2).

Since the size of B is known, we start at the (5,2) point and take out a sub-matrix of the same size as B, which is called C (actually not really taken out, just a pointer operation).

4, the B and C-point comparison, if each point of the RGB values are the same, then found a small picture.

5, according to the above results, the original large graph matrix A is divided into four sub-matrices. The basis for partitioning is the lower right point of the C matrix in a matrix. In this example is (21,6)

0000000000000000000000*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
*************************************************************************************************************** *********
0000000000000000000000*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000011111111111111111*00000000001111111111111111100000000001111111111111111100000000001111111111111111100000
0000000000000000000000*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000*00000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Because these four sub-arrays still belong to the concept of "big picture", a recursive function can be designed to complete the search of the whole large image. Just find a suitable way to save the results of the search

This method is the most efficient way to find a small rectangular image from a large image, and it is not very efficient to find irregular graphs (such as pentagram). The key is the determination of the point used to separate the large graph matrix. In general, this point is determined by the shape and size of the small chart. If the shape is weird and the key parts are likely to mesh with each other, the distance from the starting point of the graph will be smaller. Conversely, it can be larger, such as a rectangle.

Extensible aspects:

The small picture is packaged into a class, which adds contour information of the outer edge, transparent color information and so on, can achieve more complex image search function

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.