Mathematical methods of Thinking-python computing Warfare (8)-Machine vision-Two value

Source: Internet
Author: User

two value of
Hreshold

Applies a fixed-level threshold to each array element.

C + +:   double  threshold ( inputarray  src , outputarray  DST , DOUBLE&N Bsp Thresh , double maxval , int  type )
Python:   cv2. threshold ( src, thresh, maxval, type [, DST )  →retval, DST

Highlight=cvthreshold #cv2. Threshold "title=" permalink to this definition "style=" Color:rgb (101, 161, 54); Text-decoration:none; Visibility:hidden; Font-size:0.8em; padding:0px 4px; "

C: Double cvthreshold (const cvarr* src, cvarr* DST, double Threshol D, 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 type as src.
  • thresh –threshold value.
  • maxval –maximum value to use with the thresh_binary andthresh_binary_inv thresholding 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 ()  could be also used for the purpose) or for removing a noise, which is, Filte Ring out pixels with too small or too large values. There is several types of thresholding supported by the function. They is determined by type  :

  • Thresh_binary

  • Thresh_binary_inv

  • Thresh_trunc

  • Thresh_tozero

  • Thresh_tozero_inv

Also, the special value Thresh_otsu is 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 SP Ecified thresh . 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 ()

the whole content of this blog is original, if reproduced please indicate the sourcehttp://blog.csdn.net/myhaspl/





Adaptive binary

The adaptivethreshold function can be two-valued and can also extract edges:


Python: cv2. Adaptivethreshold (src, maxValue, Adaptivemethod, Thresholdtype, BlockSize, C[, DST]) →DST

C:  void Cvadaptivethreshold (Const cvarr* src, cvarr* DST, double Max_valueInt Adaptive_method=cv_adaptive_thresh_mean_c, int Threshold_type=cv_thresh_binary, int block_size=3, double param1=5 )

Highlight=cvthreshold#void cvadaptivethreshold (const cvarr* SRC, cvarr* DST, double max_value, int adaptive_method, int t Hreshold_type, int block_size, double param1) "title=" permalink to this definition "style=" Color:rgb (101, 161, 54); Text-decoration:none; Visibility:hidden; Font-size:0.8em; padding:0px 4px; " >


 
  • src –source 8-bit single-channel image.
  • DST –destination image of the same size and the same type as src .
  • 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_c oradaptive_ Thresh_gaussian_c . See the details below.
  • thresholdtype –thresholding type that must is eitherthresh_binary or thresh_binary_inv .
  • blockSize –size of a pixel neighborhood that's 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 and may are zero or negative as well.


  • The Block_size parameter determines the size of the block of the local threshold. Block very hour. such as block_size=3 or 5 or 7 o'clock, the performance of the edge extraction function. When the block_size is set to a larger value, such as block_size=21, 51, etc., it is two value

The following 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 ()

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbxloyxnwba==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>

binary such as the following:

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 ()






Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Mathematical methods of Thinking-python computing Warfare (8)-Machine vision-Two value

Related Article

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.