python_developer
1.54K subscribers
3.74K photos
1.97K videos
232 files
434 links
کانال اموزش پایتون @Real_developer
تبلیغات پذیرفته میشود.
Download Telegram
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 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 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 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 ()
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()
همانطور که در کد مشخص شده ما دو خروجی داریم:retval,threshold
ولی در Simple Thresholding
فقط از threshold استفاده میشود.
روش Simple Thresholding در عکسهای رنگی جالب نیست و خروجی آن شبیه تصویر میباشد .
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 ()
This media is not supported in your browser
VIEW IN TELEGRAM
برای #داده_کاوی ما نیاز به حجم زیادی داده داریم که این داده ها، #big_data نامیده میشود. از ویژگیهای مهم #big_data :👇👇
1) ارزشمند بودن داده ها
2)متنوع بودن داده ها
3)حجیم بودن داده ها
4)داده ها به سرعت در حال تغییر و تولید هستند
5)داده ها به درد بخور و صحیح هستند
2️⃣Adaptive Thresholding

در آستانه تطبیقی ، مانند آستانه ساده از مقدار سراری برای آستانه استفاده نمیشود. چون عکس هایی که دارای روشنایی متفاوت در قسمتهای مختلف میباشند خروجی جالبی ندارند.
بنابراین در این روش ، آستانه برای یک قسمت کوچکی از تصویر حساب میشود وبا این مقادیر ، به نتایج بهتری در تصاویر با نورهای متفاوت میرسیم.
در روش تطبیقی ما سه ورودی و یک خروجی خواهیم داشت:
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('sample.jpg',0)
img = cv2.medianBlur(img,5)

ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2)
th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
titles = ['Original Image', 'Global Thresholding (v = 127)','Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
images = [img, th1, th2, th3]
for i in xrange(4):
plt.subplot(2,2,i+1),plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
python_developer
Photo
♦️تفاوت آستانه ساده با تطبیقی در این تصویر مشهود است♦️