-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary_image.py
32 lines (26 loc) · 1 KB
/
binary_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
# @Time : 2020/4/2 下午5:42
# @Author : LuoLu
# @FileName: binary_image.py
# @Software: PyCharm
# @Github :https://github.com/luolugithub
# @E-mail :[email protected]
import matplotlib
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
from PIL.Image import Image
path = "/home/luolu/PycharmProjects/ParticleDetection/data/yashi_qscan/color/fen_color.png"
original = cv.imread(path)
height, width, channels = original.shape
src = cv.GaussianBlur(original, (1, 1), 0)
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
# cv.THRESH_BINARY | cv.THRESH_OTSU "ct.png"
ret, binary_ = cv.threshold(gray, 0, 255, cv.THRESH_BINARY | cv.THRESH_TRIANGLE)
# 使用开运算去掉外部的噪声
# kernel = cv.getStructuringElement(cv.MORPH_RECT, (11, 11))
# binary = cv.morphologyEx(binary_, cv.MORPH_OPEN, kernel)
cv.imshow('binary', binary_)
# cv.imwrite("/home/luolu/PycharmProjects/ParticleDetection/data/yashi_qscan/binary_test.png", binary_)
cv.waitKey(0)
cv.destroyAllWindows()