|
a |
|
b/features/feature.py |
|
|
1 |
from .otsu import * |
|
|
2 |
#from FeatureExtract import * |
|
|
3 |
import cv2 |
|
|
4 |
import numpy as np |
|
|
5 |
from skimage import io |
|
|
6 |
import scipy.misc |
|
|
7 |
|
|
|
8 |
def truncate_hu(image_array, max = 400, min = -900): |
|
|
9 |
image = image_array.copy() |
|
|
10 |
image[image > max] = max |
|
|
11 |
image[image < min] = min |
|
|
12 |
return image |
|
|
13 |
''' |
|
|
14 |
edge不用这个函数了,比较慢 |
|
|
15 |
''' |
|
|
16 |
def edge_detection(img): |
|
|
17 |
# gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # 转换为灰度图 |
|
|
18 |
# img = truncate_hu(gray) |
|
|
19 |
img = truncate_hu(img) |
|
|
20 |
|
|
|
21 |
x = cv2.Sobel(img, cv2.CV_16S, 1, 0) |
|
|
22 |
y = cv2.Sobel(img, cv2.CV_16S, 0, 1) |
|
|
23 |
#z = cv2.Sobel(img, cv2.CV_16S, 1, 1) |
|
|
24 |
|
|
|
25 |
absX = cv2.convertScaleAbs(x) # 转回uint8 |
|
|
26 |
absY = cv2.convertScaleAbs(y) |
|
|
27 |
#absz = cv2.convertScaleAbs(z) |
|
|
28 |
|
|
|
29 |
dst = cv2.addWeighted(absX,0.5,absY,0.5,0) |
|
|
30 |
return dst |
|
|
31 |
|
|
|
32 |
''' |
|
|
33 |
otsu还没找到代替的 |
|
|
34 |
''' |
|
|
35 |
def otsu(img): |
|
|
36 |
# gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # 转换为灰度图 |
|
|
37 |
# otsu_img = otsu_helper(gray, upper=118, down = 45,categories=1) |
|
|
38 |
otsu_img = otsu_helper(img, categories=1) |
|
|
39 |
return otsu_img |