-
Notifications
You must be signed in to change notification settings - Fork 0
/
elimination.py
56 lines (48 loc) · 1.43 KB
/
elimination.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
# elimination.py
import numpy as np
import scipy
import pylab
import pymorph
import mahotas
import skimage.io as io
import pandas as pd
from scipy import ndimage
#Prints roundness of one image on terminal
# def main():
# centregalaxy = eliminate(153666) #Galaxyid goes here
# print centregalaxy
# pylab.imshow(centregalaxy)
# pylab.show()
#Creates csv file for roundness of all images
def main():
images = io.ImageCollection('1*****.jpg')
n = len(images)
indices = np.empty(n)
roundness = np.empty(n)
for i in range(n):
indices[i] = images.files[i][0:6]
roundness[i] = eliminate(indices[i])
R = {'Roundness':roundness}
table = pd.DataFrame(R,index=indices)
table.to_csv('roundness.csv')
# Returns a 3 dimentional array True/False or Returns roundness
# Its shape is (424,424,3)
def eliminate(galaxyid):
filename = str(galaxyid)[0:6]+'.jpg'
#First, we load the image
pic = mahotas.imread(filename)
#Smooth the image using a Gaussian filter
picf = ndimage.gaussian_filter(pic, 8)
T = mahotas.thresholding.otsu(picf)
#Label each blob in the image
labeled,nr_objects = ndimage.label(picf > T)
#Getting rid of blobs that are not our target galaxy
centre = (labeled==labeled[212,212,1])
perimiter = mahotas.labeled.bwperim(centre)
p = np.sum(perimiter)
area = np.sum(centre)
roundness = (p*p/(4*np.pi))/area
return roundness #The lower 'roundness' is, the rounder the galaxy is
#return centre
if __name__ == "__main__":
main()