> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aic-eec.com/artificial-intelligence-ai/basic-image-processing/computer-vision-for-python/lab-2-basic-cv/simple-thresholding.md).

# Simple Thresholding

&#x20;    Threshold คือ หนึ่งในเทคนิคการคัดแยกวัตถุออกจากภาพพื้นหลัง โดยการรับภาพสีเทามาแปลงเป็นภาพไบนารีที่มีค่าพิกเซลเป็น 0 หรือ 255 ด้วยการกำหนดค่าคงที่ขั้นต่ำมาเทียบกับค่าพิกเซลในแต่ละพื้นที่ของภาพสีเทา เพื่อทำการเปลี่ยนค่าพิกเซลนั้นเป็น 0 หรือ 255&#x20;

```
$ (T, threshImage) = cv2.threshold(image, thresh, maxval, type)
```

**Parameters:**

* image => ภาพระดับสีเทาที่จะนำมาใช้ในการ Threshold
* thresh => ค่าความสว่างขั้นต่ำที่นำมาใช้ในการเทียบกับค่าพิเซลใภาพระดับสีเทา
* maxval => ค่าความสว่างสูงสุดที่ต้องการ
* type => ประเภท Threshold&#x20;

\
**Example:**

```
import cv2
image = cv2.imread("/path/your/image.jpg")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (7, 7), 0)
cv2.imshow("Image", image)

(T, threshInv) = cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY_INV)
cv2.imshow("Threshold Binary Inverse", threshInv) 

(T, thresh) = cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY)
cv2.imshow("Threshold Binary", thresh)
 
cv2.imshow("Output", cv2.bitwise_and(image, image, mask=threshInv))
cv2.waitKey(0)
```

![](https://paper-attachments.dropbox.com/s_ED8F33D726DEEB274B91070CD54DD9822C8EEE25152706EDC8932020507EB3FC_1600709144212_Screenshot+from+2020-09-22+00-25-20.png)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aic-eec.com/artificial-intelligence-ai/basic-image-processing/computer-vision-for-python/lab-2-basic-cv/simple-thresholding.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
