forked from BATspock/TextonsSeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvolve_LM_filters.py
46 lines (39 loc) · 2.69 KB
/
convolve_LM_filters.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
import cv2
import sys
import numpy as np
class preprocessImageWithKernels(object):
"""
create vector features after applying kernels
"""
def __init__(self, image, image_color):
#convert image to grayscale
self.im = image
self.im_color = image_color
def merge(self):
"""
apply gaussian blur
"""
self.out = cv2.GaussianBlur(self.im,(7,7),0)
self.out_color = cv2.GaussianBlur(self.im_color,(7,7),0)
def apply_kernel(self, kernels):
"""
apply LM filter kernels on the image after preprocessing
"""
image = []
for i in range(kernels.shape[2]):
image.append(cv2.filter2D(self.out, -1, kernels[:,:,i]))
self.image_after_filters = np.array(image)
#print("creating filtered image...")
#print(self.image_after_filters.shape)
def create_vectors(self):
"""
return vectors created for each pixel
"""
point_vector = list()
for row in range(self.image_after_filters.shape[1]):
for col in range(self.image_after_filters.shape[2]):
point_vector.append(self.image_after_filters[:,row, col])
self.pixel_point_vector = np.array(point_vector)
#print(self.pixel_point_vector.shape)
#print("initial vector...")
return self.pixel_point_vector, self.out_color