Skip to content

Commit

Permalink
multiprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
djjayeeta committed May 12, 2017
1 parent 6b2eaeb commit 8db34c0
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions fuzzy_c_spatial_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
neg_dist = 0
cluster_number = 6
cluster_color = {0:[255,255,0],1:[128,255,0],2:[0,128,255],3:[255,0,255],4:[255,0,0],5:[0,0,0]}
image_path = "IMS1_HYSI_GEO_114_05FEB2009_S1_TOA_REFLECTANCE_07_SPBIN.tif"
image_path = "test_new.jpeg"
maxconn=8
pool=threading.BoundedSemaphore(value=maxconn)
dist_mat = []
Expand All @@ -37,18 +37,18 @@ def calculate_fuzzy_index(itertion_number,h,fxkyk):

def get_data_from_image():
global image_path
# M = np.asarray(Image.open(image_path))
dataset = gdal.Open(image_path,gdal.GA_ReadOnly)
col = dataset.RasterXSize
row = dataset.RasterYSize
# print dataset.RasterCount
a = [[[]for y in xrange(col)] for z in xrange(row)]
for i in xrange(1,dataset.RasterCount + 1):
band = dataset.GetRasterBand(i).ReadAsArray()
for m in xrange(0,row):
for n in xrange(0,col):
a[m][n].append(band[m][n])
M = np.array(a,dtype='uint16')
M = np.asarray(Image.open(image_path))
# dataset = gdal.Open(image_path,gdal.GA_ReadOnly)
# col = dataset.RasterXSize
# row = dataset.RasterYSize
# # print dataset.RasterCount
# a = [[[]for y in xrange(col)] for z in xrange(row)]
# for i in xrange(1,dataset.RasterCount + 1):
# band = dataset.GetRasterBand(i).ReadAsArray()
# for m in xrange(0,row):
# for n in xrange(0,col):
# a[m][n].append(band[m][n])
# M = np.array(a,dtype='uint16')
image_name = image_path.split(".")[0]
f = open("data_"+str(image_name)+".pickle","wb")
# f = open("data_test.pickle","wb")
Expand Down Expand Up @@ -253,17 +253,20 @@ def get_cluster_ref(U,data,v,v_denom):
return v

def calculate_distance(params):
global dist_mat
global cluster_number
# global dist_mat
# print dist_mat
n,m,U,itertion_number,data,cluster_centres = params[0],params[1],params[2],params[3],params[4],params[5]
# print n,m
cluster_number = len(cluster_centres)
# cluster_number = len(cluster_centres)
cluster_spatial_arr,alpha = spatial_dist_denom(n,m,U,itertion_number)
dist = [0 for i in xrange(0,cluster_number)]
for r in xrange(0,cluster_number):
dist = eu_distance(data[m][n],cluster_centres[r]) + spatial_distance(r,cluster_spatial_arr,alpha)
dist[r] = eu_distance(data[m][n],cluster_centres[r]) + spatial_distance(r,cluster_spatial_arr,alpha)
# if dist != dist_mat[m][n][r]:
# print 'yes',m,n,r
dist_mat[m][n][r] = dist
# dist_mat[m][n][r] = dist
return dist

class GrabUrl(threading.Thread):
def __init__(self, arg0):
Expand Down

0 comments on commit 8db34c0

Please sign in to comment.