Path to mathematics-python computing practice (8)-machine vision-image binarization-python practice

Source: Internet
Author: User

Path to mathematics-python computing practice (8)-machine vision-image binarization-python practice

Binarization
Hreshold

Applies a fixed-level threshold to each array element.

C ++:  Double Threshold (InputArray Src, OutputArray Dst, Double Thresh, Double Maxval, Int Type )
Python:   Cv2. Threshold (Src, thresh, maxval, type [, dst] )→ Retval, dst
C:  Double CvThreshold (Const CvArr * Src, CvArr * Dst, Double Threshold, Double Max_value, Int Threshold_type )
Parameters:
  • Src-Input array (single-channel, 8-bit or 32-bit floating point ).
  • Dst-Output array of the same size and typeSrc.
  • Thresh-Threshold value.
  • Maxval-Maximum value to use withTHRESH_BINARYAndTHRESH_BINARY_INVThresholding types.
  • Type-Thresholding type (see the details below ).

The function applies fixed-level thresholding to a single-channel array. The function is typically used to get a bi-level (binary) image out of a grayscale image (Compare ()Cocould be also used for this purpose) or for removing a noise, that is, filtering out pixels with too small or too large values. there are several types of thresholding supported by the function. they are determinedType:

  • THRESH_BINARY

  • THRESH_BINARY_INV

  • THRESH_TRUNC

  • THRESH_TOZERO

  • THRESH_TOZERO_INV

Also, the special valueTHRESH_OTSUMay be combined with one of the above values. In this case, the function determines the optimal threshold value using the Otsu's algorithm and uses it instead of the specifiedThresh. The function returns the computed threshold value. Currently, the Otsu's method is implemented only for 8-bit images.


import cv2fn="test3.jpg"myimg=cv2.imread(fn)img=cv2.cvtColor(myimg,cv2.COLOR_BGR2GRAY)retval, newimg=cv2.threshold(img,40,255,cv2.THRESH_BINARY)cv2.imshow('preview',newimg)cv2.waitKey()cv2.destroyAllWindows()

All content of this blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/





Adaptive binarization

The adaptiveThreshold function is optional.Binarization, Edge Extraction:


Python: Cv2.AdaptiveThreshold(Src, maxValue, adaptiveMethod, thresholdType, blockSize, C [, dst])→ Dst

C:  Void CvAdaptiveThreshold (Const CvArr * Src, CvArr * Dst, Double Max_value, Int Adaptive_method= CV_ADAPTIVE_THRESH_MEAN_C, int Threshold_type= CV_THRESH_BINARY, int Block_size= 3, double Param1= 5 )


 
  • Src-Source 8-bit single-channel image.
  • Dst-Destination image of the same size and the same typeSrc.
  • MaxValue-Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.
  • AdaptiveMethod-Adaptive thresholding algorithm to use,ADAPTIVE_THRESH_MEAN_COrADAPTIVE_THRESH_GAUSSIAN_C. See the details below.
  • ThresholdType-Thresholding type that must be eitherTHRESH_BINARYOrTHRESH_BINARY_INV.
  • BlockSize-Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.
  • C-Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.


  • The block_size parameter determines the block size of the local threshold. The block size is very small, for example, when block_size = 3 or 5 or 7, it is represented by the edge extraction function. When block_size is set to a relatively large value, such as block_size = 21 and 51, It is binarization.

Below is the extraction edge
import cv2fn="test3.jpg"myimg=cv2.imread(fn)img=cv2.cvtColor(myimg,cv2.COLOR_BGR2GRAY)newimg=cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,5,2)cv2.imshow('preview',newimg)cv2.waitKey()cv2.destroyAllWindows()


Binarization:

import cv2fn="test3.jpg"myimg=cv2.imread(fn)img=cv2.cvtColor(myimg,cv2.COLOR_BGR2GRAY)newimg=cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,51,2)cv2.imshow('preview',newimg)cv2.waitKey()cv2.destroyAllWindows()







Computes the number of white points in the framed area after opencv image binarization

This is a simple traversal of the image. Is it okay to calculate the number of points with a value of 255 in the selected area?

An image has been known, how to detect the similarity between the two images after the binarization, that is, how to know the error values of the two images, after the binarization

The idea of Stephen Hawking is more acceptable: The universe is limited and unbounded, but a few more dimensions than the Earth. For example, our earth is finite and unbounded. On the earth, whether from the south pole to the north pole or from the north pole to the South Pole, you can never find the boundaries of the earth, but you cannot think that the Earth is infinite. In fact, we all know that the Earth is limited. So are the Earth and the universe.

How can we understand that the universe is more than the Earth? For example, a ball rolls along the ground and falls into a small hole. In our opinion, the ball exists, and it is still in the cave, because we humans are "3D; for an animal, the conclusion is: the ball no longer exists! It disappears. Why do we come to this conclusion? Because it lives in a "two-dimensional" World, it cannot be clearly understood about "three-dimensional" events. In the same way, we humans live in the "3D" world, and it is hard to understand the universe that is a few more dimensions than us. This is precisely why the question "What is the universe?" cannot be clearly explained.

1. Even universe

For a long time, people believe that the Earth is the center of the universe. Gobaini turned this idea upside down and thought that the sun was the center of the universe. The Earth and other planets rotate around the sun, and the stars are embedded in the outermost layer of the celestial sphere. Bruno further believes that there is no center in the universe, and stars are distant suns.

The universe is limited, either by tolemi or by cobaini. The church supports the limitations of the universe. However, Bruno dared to say that the universe was infinite, which aroused a long-term debate on whether the universe was limited or unlimited. The debate did not stop because the church burned Bruno. Those who advocate the limited universe say, "How can the universe be infinite ?" It is indeed difficult to clarify this issue. "How can the universe be limited ?" This question is also hard to answer.

With the development of astronomical observation technology, we can see that, as Bruno said, stars are distant suns. It is further recognized that the galaxy is a large galaxy composed of countless solar systems. Our solar system is at the edge of the Milky Way and rotates around the center of the Milky Way, with a speed of about 250 km per second, it takes about 0.25 billion years to turn around Yinxin. The diameter of the solar system is at best about 1 light year, while the diameter of the galaxy is as high as 0.1 million light years. The Milky Way is composed of more than 100 billion stars, and the position of the solar system in the Milky Way is like a sand in the city of Beijing. Later, we found that our galaxy is also a larger group of galaxy clusters with other galaxy clusters, with a diameter of about 107 light years (10 million light years ). At present, the telescope has been more than 10 billion light years of observation. Within the observed range, there are countless galaxy clusters, which are no longer larger but evenly distributed to the same sex. That is to say, the matter is distributed in groups under the scale of 10 to the power of 7 light years. Satellites rotate around the planet, while planets and comet rotate around the stars to form a solar system. These solar systems are composed of one, two, three or more suns and their planets. Two suns are called double stars, and more than three suns are called star series. Hundreds of billions of solar systems gather together to form the Milky Way, and the stars that make up the Milky Way (the solar system) rotate around the same center of gravity-the silver heart. Countless Milky Ways form a group of galaxy clusters, and each galaxy in the group also rotates around their common center of gravity. However, there is no longer a group structure between galaxy clusters. Each galaxy group is evenly distributed and irregularly moving. From the perspective of our Earth, the situation is similar. Roughly speaking, the points inherent in a galaxy are like gas molecules in a container, evenly distributed and irregularly moving. That is to say, at a scale above 10 to the power of eight light years (0.1 billion light years), the material distribution in the universe is not a mass, but even distribution. Because it takes time for light to spread, the galaxy we see 0.1 billion light years ago is actually the one in that galaxy. So what we see with a telescope is not only a space distant galaxy, but also their past. From the telescope's perspective, no matter how long the galaxy clusters are, they are evenly distributed to the same sex.

Therefore, we can think that the material distribution on the Yuguan Scale (10 to the power of 5 light years or more) is not present, but has long been so.

As a result, the celestial physicist proposed a rule, the so-called cosmic principle. This article... the remaining full text>
 

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.