-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessing.py
More file actions
62 lines (47 loc) · 1.42 KB
/
preprocessing.py
File metadata and controls
62 lines (47 loc) · 1.42 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
import requests
from PIL import Image, ImageFilter
from io import BytesIO
import matplotlib.pyplot as plt
class Preprocessing:
def __init__(self, img):
self._img = img
self._fig = None
self._ax = None
self._pixelWidth = 1
self._units = "pixel"
def open(self, url):
response = requests.get(url)
img = Image.open(BytesIO(response.content))
self.setImage(img)
def show(self):
self._fig, self._ax = plt.subplots()
self._ax.imshow(self._img)
plt.ion()
plt.show()
def update(self):
self._ax.imshow(self._img)
plt.draw()
self._fig.canvas.draw()
def setImage(self, img):
self._img = img
def getImage(self):
return self._img
def setPixelWidth(self, pw, units):
self._pixelWidth = pw
self._units = units
def getPixelWidth(self):
return self._pixelWidth
def getUnits(self):
return self._units
def gaussianBlur(self, sigma):
img2 = self._img.filter(ImageFilter.GaussianBlur(radius=sigma))
self._img.paste(img2, (0, 0))
self.update()
def medianFilter(self, radius):
img2 = self._img.filter(ImageFilter.MedianFilter(size=2 * radius + 1))
self._img.paste(img2, (0, 0))
self.update()
def intensityNormalization(self):
pass
def subtractBackground(self, radius):
pass