def analyseGradient(imagedict): R = analysis_functions.getGradient(imagedict[RGB][:, :, RED]) G = analysis_functions.getGradient(imagedict[RGB][:, :, GREEN]) B = analysis_functions.getGradient(imagedict[RGB][:, :, BLUE]) GRAY = analysis_functions.getGradient(imagedict[grayscale]) colorlist = [] colorlist.append(mean(R)) colorlist.append(mean(G)) colorlist.append(mean(B)) colorlist.append(mean(GRAY)) colorlist.append(std(R)) colorlist.append(std(G)) colorlist.append(std(B)) colorlist.append(std(GRAY)) return colorlist
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 '''