forked from bnsreenu/python_for_microscopists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
057-ML_06_02_what are features.py
68 lines (46 loc) · 1.29 KB
/
057-ML_06_02_what are features.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
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
64
65
66
67
68
#!/usr/bin/env python
__author__ = "Sreenivas Bhattiprolu"
__license__ = "Feel free to copy, I appreciate if you acknowledge Python for Microscopists"
# https://www.youtube.com/watch?v=yUATC9tt7OM
"""
@author: Sreenivas Bhattiprolu
What are features?
"""
#A few generic filters...
import cv2
from skimage.filters.rank import entropy
from skimage.morphology import disk
import pandas as pd
img = cv2.imread('scratch.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img2 = img.reshape(-1)
df = pd.DataFrame()
df['Original Image'] = img2
entropy_img = entropy(img, disk(1))
entropy1 = entropy_img.reshape(-1)
df['Entropy'] = entropy1
#print(df)
"""
cv2.imshow('entropy', entropy_img)
cv2.waitKey()
cv2.destroyAllWindows()
"""
import cv2
from scipy import ndimage as nd
#import numpy as np
"""
img = cv2.imread('Yeast_Cells.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
"""
gaussian_img = nd.gaussian_filter(img, sigma=3)
gaussian_img1 = gaussian_img.reshape(-1)
df['Gaussian s3'] = gaussian_img1
from skimage.filters import sobel
sobel_img = sobel(img)
sobel1 = sobel_img.reshape(-1)
df['Sobel'] = sobel1
print(df.head())
cv2.imshow('Original Image', img)
cv2.imshow('gaussian', sobel_img)
cv2.waitKey(5000)
cv2.destroyAllWindows()