- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Performing truncate thresholding on an image using OpenCV
In this program, we will perform truncate thresholding on an image using openCV. Thresholding is a process in which the value of each pixel is changed in relation to a threshold value.
The pixel is given a certain value if it is less than the threshold and some other value if it is greater than the threshold. In truncate thresholding, values greater than the threshold are reduced to the threshold value. Every other pixel remains the same.
Original Image
Algorithm
Step 1: Import cv2. Step 2: Define threshold and max_val. Step 3: Pass these parameters in the cv2.threshold value and specify the type of thresholding you want to do. Step 4: Display the output.
Example Code
import cv2 image = cv2.imread('testimage.jpg') threshold_value = 120 max_val = 255 ret, image = cv2.threshold(image, threshold_value, max_val, cv2.THRESH_TRUNC) cv2.imshow('TruncateThresholding', image)
Output
- Related Articles
- Performing binary thresholding on an image using OpenCV
- Performing zero thresholding on an image using OpenCV
- Performing inverse binary thresholding on an image using OpenCV
- Performing inverse zero thresholding on an image using OpenCV
- Performing an opening operation on an image using OpenCV
- Performing a closing operation on an image using OpenCV
- How to perform Otsu's thresholding on an image using Python OpenCV?
- How to perform different simple thresholding of an image using Python OpenCV?
- How to perform adaptive mean and gaussian thresholding of an image using Python OpenCV?
- Draw an ellipse on an image using OpenCV
- Draw rectangle on an image using OpenCV
- Performing white TopHat operation on images using OpenCV
- Performing white BlackHat operation on images using OpenCV
- Draw a line on an image using OpenCV
- Histogram equalization on an image in OpenCV using Java.

Advertisements