uz
Feedback

Firibgarlarga uchmang! Telemetrio bunday kanallarni topadi va belgilaydi 👉 Belgini ko‘rmoqchi bo‘lsangiz, obuna bo‘ling

python_developer

python_developer

Kanalga Telegram’da o‘tish

کانال اموزش پایتون @Real_developer تبلیغات پذیرفته میشود.

Ko'proq ko'rsatish
1 519
Obunachilar
Ma'lumot yo'q24 soatlar
-37 kun
-430 kun
Postlar arxiv
#THRESH_TOZERO_INV
#THRESH_TOZERO_INV

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 ()

#THRESH_TOZERO
#THRESH_TOZERO

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 ()

#THRESH_TRUNC
#THRESH_TRUNC

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 ()

#THRESH_BINARY_INV
#THRESH_BINARY_INV

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 ()

#THRESH_BINARY
#THRESH_BINARY

عکس منبع
عکس منبع

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 ()

تصویر منتخب
تصویر منتخب

Simple Thresholding اگر مقدار پیکسل از مقدار آستانه بزرگتر باشد،یک مقدار میگیره (ممکنه اون سفید باشه) و اگر کمتر باشه (ممکنه اون مقدار سیاه باشه). در آستانه گیری ساده ا ز تابع cv2.threshold استفاده میکنیم. - اولین آرگومان این تابع مربوط به تصویر اولیه میباشد که باید سیاه و سفید باشد. - آرگومان دوم مقدار آستانه ای که برای طبقه بندی مقادیر پیکسل استفاده میشود. - آرگومان سوم maxVal که نشان دهنده بیشترین مقدار از مقدار آستانه است. - سبک های مختلف آستانه توسط آرگومان چهارم مشخص میشود: cv2.THRESH_BINARY cv2.THRESH_BINARY_INV cv2.THRESH_TRUNC cv2.THRESH_TOZERO cv2.THRESH_TOZERO_INV

سه روش آستانه گیری: + Simple thresholding + Adaptive thresholding + Otsu's thresholding

AnimatedSticker.tgs0.35 KB

photo content

import numpy as np import cv2 import matplotlib.pyplot as plt img = cv2.imread('5.jpg') img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) blue_min = np.array([100, 100, 100], np.uint8) blue_max = np.array([140, 255, 255], np.uint8) mask_inverse = cv2.inRange(img_hsv, blue_min, blue_max) mask = cv2.bitwise_not(mask_inverse) plt.imshow(cv2.cvtColor(mask, cv2.COLOR_GRAY2RGB)) mask_rgb = cv2.cvtColor(mask, cv2.COLOR_GRAY2RGB) masked_upstate = cv2.bitwise_and(img, mask_rgb) masked_replace_white = cv2.addWeighted(masked_upstate, 1, cv2.cvtColor(mask_inverse, cv2.COLOR_GRAY2RGB), 1, 0) plt.imshow(cv2.cvtColor(masked_replace_white, cv2.COLOR_BGR2RGB)) plt.show()

Using binary thresholding to obtain an image mask
Using binary thresholding to obtain an image mask

import numpy as np import cv2 import matplotlib.pyplot as plt img = cv2.imread('5.jpg') img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) blue_min = np.array([100, 100, 100], np.uint8) blue_max = np.array([140, 255, 255], np.uint8) mask_inverse = cv2.inRange(img_hsv, blue_min, blue_max) mask = cv2.bitwise_not(mask_inverse) plt.imshow(cv2.cvtColor(mask, cv2.COLOR_GRAY2RGB)) plt.show()