This media is not supported in your browser
VIEW IN TELEGRAM
سه روش آستانه گیری:
+ Simple thresholding
+ Adaptive thresholding
+ Otsu's thresholding
+ Simple thresholding
+ Adaptive thresholding
+ Otsu's thresholding
Simple Thresholding
اگر مقدار پیکسل از مقدار آستانه بزرگتر باشد،یک مقدار میگیره (ممکنه اون سفید باشه) و اگر کمتر باشه (ممکنه اون مقدار سیاه باشه).
در آستانه گیری ساده ا ز تابع cv2.threshold استفاده میکنیم.
- اولین آرگومان این تابع مربوط به تصویر اولیه میباشد که باید سیاه و سفید باشد.
- آرگومان دوم مقدار آستانه ای که برای طبقه بندی مقادیر پیکسل استفاده میشود.
- آرگومان سوم maxVal که نشان دهنده
بیشترین مقدار از مقدار آستانه است.
- سبک های مختلف آستانه توسط آرگومان چهارم مشخص میشود:
cv2.THRESH_BINARY
cv2.THRESH_BINARY_INV
cv2.THRESH_TRUNC
cv2.THRESH_TOZERO
cv2.THRESH_TOZERO_INV
اگر مقدار پیکسل از مقدار آستانه بزرگتر باشد،یک مقدار میگیره (ممکنه اون سفید باشه) و اگر کمتر باشه (ممکنه اون مقدار سیاه باشه).
در آستانه گیری ساده ا ز تابع cv2.threshold استفاده میکنیم.
- اولین آرگومان این تابع مربوط به تصویر اولیه میباشد که باید سیاه و سفید باشد.
- آرگومان دوم مقدار آستانه ای که برای طبقه بندی مقادیر پیکسل استفاده میشود.
- آرگومان سوم maxVal که نشان دهنده
بیشترین مقدار از مقدار آستانه است.
- سبک های مختلف آستانه توسط آرگومان چهارم مشخص میشود:
cv2.THRESH_BINARY
cv2.THRESH_BINARY_INV
cv2.THRESH_TRUNC
cv2.THRESH_TOZERO
cv2.THRESH_TOZERO_INV
import cv2
import numpy as np
img = cv2.imread('sample.jpg',0)
retval,threshold = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
cv2.imshow('Original ',img)
cv2.imshow('threshold ',threshold)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import numpy as np
img = cv2.imread('sample.jpg',0)
retval,threshold = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
cv2.imshow('Original ',img)
cv2.imshow('threshold ',threshold)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import cv2
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import cv2
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import cv2
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import cv2
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import numpy as np
img = cv2.imread('sample.jpg',0)
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
This media is not supported in your browser
VIEW IN TELEGRAM
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('8.jpg',0)
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]
for i in xrange(6):
plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('8.jpg',0)
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]
for i in xrange(6):
plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
همانطور که در کد مشخص شده ما دو خروجی داریم:retval,threshold
ولی در Simple Thresholding
فقط از threshold استفاده میشود.
ولی در Simple Thresholding
فقط از threshold استفاده میشود.
python_developer
روش Simple Thresholding در عکسهای رنگی جالب نیست و خروجی آن شبیه تصویر میباشد .
import cv2
import numpy as np
img = cv2.imread('sample.jpg')
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
import numpy as np
img = cv2.imread('sample.jpg')
ret,threshold1 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
cv2.imshow('threshold ',threshold1)
cv2.waitKey (0)
cv2.destroyAllWindows ()
This media is not supported in your browser
VIEW IN TELEGRAM