پردازش تصویر با پایتون قسمت شانزدهم

آستانه گذاری ساده

( Truncate Thresholding ( type = THRESH_TRUN

در این نوع آستانه، پیکسل مقصد به آستانه (thresh) تنظیم می شود اگر مقدار پیکسل منبع بیشتر از آستانه باشد. در غیر این صورت آن را به مقدار پیکسل منبع تنظیم میکنیم. maxValue نادیده گرفته شده است.

الگوریتم:

if src(x,y) > thresh
dst(x,y) =thresh
else
dst(x,y) =src(x,y)

توجه داشته باشید که تمام مقادیر بالای آستانه (۱۲۷) به ۱۲۷ تنظیم شده و تمام مقادیر کمتر یا برابر ۱۲۷ بدون تغییر هستند.

maxValue نادیده گرفته شده است

کد:

import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('threshold.png',0)
ret,thresh1 = cv2.threshold(img,0,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,0,127,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
titles = ['Original Image','THRESH_BINARY','THRESH_BINARY_INV','THRESH_TRUNC']
images = [img, thresh1, thresh2,thresh3]
for i in range(4):
plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()

th3th5


دیدگاهتان را بنویسید

We are glad you have chosen to leave a comment. Please keep in mind that comments are moderated according to our comment policy.