forked from ALavault/Sequence-Test
/
DoP_histograms.py
57 lines (50 loc) · 1.48 KB
/
DoP_histograms.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 26 15:48:24 2017
@author: viper
"""
import os
import matplotlib
matplotlib.use('pgf')
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage import morphology
from skimage import color
from skimage import segmentation
from skimage import feature
from skimage import exposure
from sklearn import cluster
from skimage.util import img_as_float
from skimage.util import img_as_ubyte
import PIL.Image as Image
def thresholding(image, mini, maxi):
image = img_as_float(image)
labels = np.zeros(image.shape)
w,h = image.shape
for i in range(w):
for j in range(h):
if image[i,j]>=mini and image[i,j]<=maxi:
labels[i,j] = 1
else:
()
return labels
plt.close('all') # Close all remaining figures
fileList = os.listdir(os.getcwd()+'/move1-polar/')
i=1
# Try to get a pattern from histograms
for filename in fileList:
try :
if filename[0] == 'D':
im = io.imread('move1-polar/' + filename)
im = img_as_ubyte(im)
hist, bins = exposure.histogram(im)
m = 1./np.max(bins)
bins = m*bins
#plt.plot(bins, hist)
labels = thresholding(im, 0.2, 0.3)
plt.imshow(labels)
plt.savefig('misc2/' + filename)
except IOError :
print(filename+' : Not a file or not an image (IOError). This file will be skipped.')