-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfeature_binary.py
More file actions
63 lines (52 loc) · 1.91 KB
/
feature_binary.py
File metadata and controls
63 lines (52 loc) · 1.91 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 21 11:51:32 2019
@author: 77433
"""
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
import ROI_completed as RC
kernel=np.ones((7,7),dtype="uint8")
kernel1=np.array([[0,1,0],
[1,1,1],
[0,1,0]],dtype='uint8')
kernel2=np.ones((3,5),dtype="uint8")
kernel3=np.ones((5,3),dtype="uint8")
#cv.imwrite("./device1_clahe/clahe_test1.bmp",clahe_test1)
#cv.imwrite("clahe_test1.bmp",clahe_test1)
def open_operation(img,kernel,kernel1):
img=cv.erode(img,kernel1)
img=cv.dilate(img,kernel)
return img
def close_operation(img,kernel,kernel1): # kernel for dilation,kernel1 for erosion
img=cv.dilate(img,kernel)
img=cv.erode(img,kernel1)
return img
def feature_binary(path='0',img=None): #img 是经过get_ROI处理过的ROI图片
kern = cv.getGaborKernel((17,17),4,0,10,0.5,0,ktype=cv.CV_64F)
kern2 = cv.getGaborKernel((17,17),4,np.pi/2,10,0.5,0,ktype=cv.CV_64F)
if path!='0':
img=cv.imread(path,0)
ROI=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
fimg = cv.filter2D(ROI,cv.CV_8UC3,kern)
fimg2=cv.filter2D(ROI,cv.CV_8UC3,kern2)
ret,fimg_b=cv.threshold(fimg,230,255,cv.THRESH_BINARY_INV)
ret,fimg2_b=cv.threshold(fimg2,245,255,cv.THRESH_BINARY_INV)
orimg=cv.bitwise_or(fimg_b,fimg2_b)
result=close_operation(orimg,kernel,kernel)
result=cv.erode(result,kernel1)
return result
if __name__ =="__main__":
path1="clahe_test2.bmp"
ROI=RC.get_ROI(path1)
dst=feature_binary(img=ROI)
cv.imshow("ROI",ROI)
cv.imshow("feature",dst)
k=cv.waitKey(0)
if k == 27: # wait for ESC key to exit
cv.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
outpath="feature_"+path1
cv.imwrite(outpath,dst)
cv.destroyAllWindows()