def process(line,d):
    line = line.strip().split(tab)
    sample=line[1]
    image=line[0]
    featureimages=line[2:]
    img=Image.open(image)
    images=imageTransforms.normalizeImage(img) #Arjun's thing
    features=[]
    featurecoordinates=[]
    labels=[]
    for j in xrange(len(featureimages)):
        c=getcoordinates.getcoordinates(featureimages[j],sample)
        for i in xrange(len(c)):
            featurecoordinates.append(c[i])
        del c
    for j in xrange(len(featurecoordinates)):
        a=d.get(featurecoordinates[j][5],0)
        m=max([a,featurecoordinates[j][2]-featurecoordinates[j][0],featurecoordinates[j][3]-featurecoordinates[j][1]])
        d[featurecoordinates[j][5]]=m
    for j in xrange(len(featurecoordinates)):
        newfeature=runtraininganalysis(images[RGB],featurecoordinates[j])
        if newfeature:
            for i in xrange(len(newfeature)):
                features.append(newfeature[i])
                print("new feature",i)
            labels.append(featurecoordinates[j][4]+"_"+featurecoordinates[j][5])
            labels.append(featurecoordinates[j][4]+"_"+featurecoordinates[j][5])
            labels.append(featurecoordinates[j][4]+"_"+featurecoordinates[j][5])
            labels.append(featurecoordinates[j][4]+"_"+featurecoordinates[j][5])
    return labels,features,d
def runWalk(imgline,size,ML):
    '''
    Input:
        The line containing the image
        The window size
        the object of type ml
    Output:
        A series of arrays of the different subtypes of the image
    '''
    fillThreshold=0.1
    line = imgline.strip().split('\t')
    img = line[0]
    img = Image.open(img)
    imgs = imageTransforms.normalizeImage(img)
    x,y,step=getWalkerParameters(imgs[grayscale],size,factor=2)

    arraydict = []
    for key in ML.intdict.keys():
        arraydict.append(np.zeros_like(imgs[grayscale],dtype=int))
        temp=ML.intdict[key]

    #make binary image mask by thresholding for each object label (neuron, astrocyte, ...)
    tempColorImg=imgs['RGB']
    imageMasks=ML.maskGen.getAllMasks(tempColorImg, 'LDA')
    saveImages(imageMasks, ML.intdict)
    '''
    for i in x:
        for j in y:
            print
            print i,i+size,j,j+size,
            subMask=imageMask[j:j+size, i:i+size]
        subMask=float(subMask.sum())
        percentFilled=subMask/(size*size)
        #if subregion has enough 1's in it, the go ahead, else do nothing
        if(percentFilled>=fillThreshold):
        try:
            f=np.array(calculatefeatures(imgs,left=i,right=i+size,top=j+size,bottom=j),dtype=float)
            labels = ML.getLabels(f)
            for k in xrange(len(labels)):
            print ML.intdict[labels[k]],
            arraydict[labels[k]]=iterRegions(i,j,size,arraydict[labels[k]])
        except ValueError:
                    for i in xrange(len(vector)):
                        print vector[i],
            else:
                print "skipping"
    saveImages(nimages,ML.intdict,threshold=t)
    
    print 'Finding Local Maxima'
    markers = getSeeds(imageMask)
    print 'Running Watershed'
    watersheded = runWatershed(markers,imageMask)
    print watersheded.shape
    imsave('watersheded_image.tif', watersheded)
    '''
    savearray(imgs['grayscale'],'grayscale.tif')
    gradient = analysis_functions.getGradient(imgs['grayscale'])
    savearray(gradient,'gradient.tif')

    print
    #running watershed on GRADIENT images for all objects/ masks
    segments = {}
    for key in imageMasks.keys():
	x = imageMasks[key]
	gx = gradient*x
	s, sb=getSeeds(x)
	print 'Running Watershed on Gradient'

	rwGradient = runWatershed(s,gx)
	#savearray(sb, ML.intdict[key]+"centersBinary-Grad.tiff")
	#savearray(s, ML.intdict[key]+"centers-Grad.tiff")
	savearray(rwGradient,ML.intdict[key]+'_watershed_on_gradient.tif')
	segments[key]=rwGradient

    #running watershed on GRAYSCALE images for all objects/ masks
    for key in imageMasks.keys():
        x = imageMasks[key]
        gx = imgs['grayscale']*x
        s, sb=getSeeds(x)
        print 'Running Watershed on Grayscale'        
        rwGray = runWatershed(s,gx)
	#savearray(sb, ML.intdict[key]+"centersBinary-GrayScale.tiff")
	#savearray(s, ML.intdict[key]+"centers-GrayScale.tiff")
        savearray(rwGray,ML.intdict[key]+'_watershed_on_grayscale.tif')
        segments[key]=rwGray

    '''