def processImage(self): log.debug("IMAGE: " + self.image.z + ',' + self.image.t + ',' + self.image.ch) print 'In process image' if int(self.image.z) == 1 and int(self.image.t) == 1 and (int(self.image.ch) ==1 or int(self.image.ch) == 3): # read image from Bisque system resp, content = request(self.image.src + '?format=png', "GET", userpass = self.userpass ) print str(resp) print len(content) tempinfile = 'ac_in.png' tempoutfile = 'ac_out.png' f = open(tempinfile,'w') f.write(content) f.close() print 'Done writing the file' InitialDistance = 5.0 seg.doSegment(tempinfile,tempoutfile, self.seedX, self.seedY, InitialDistance, self.Sigma, self.SigmoidAlpha, self.SigmoidBeta,self.PropagationScaling) print 'Segmentation done!' buffer = open(tempoutfile,'r') print ' posting the output to the server ..' file = [('upload', tempoutfile, buffer.read())] resp, content = post_files (self.client_server + '/bisquik/upload_raw_image', file, [], userpass = self.userpass,) log.debug("RESP: " + str(content)) self.image_out_url = str(content)
def processImage(self): log.debug("IMAGE: " + self.image.z + ',' + self.image.t + ',' + self.image.ch) print 'In process image' if int(self.image.z) == 1 and int(self.image.t) == 1 and (int( self.image.ch) == 1 or int(self.image.ch) == 3): # read image from Bisque system resp, content = request(self.image.src + '?format=tiff', "GET", userpass=self.userpass) print str(resp) print len(content) tempinfile = 'in.tiff' tempoutfile = 'out.tiff' f = open(tempinfile, 'w') f.write(content) f.close() print 'Done writing the file' # define all the input values for now #seedX = 81 #seedY = 114 #Sigma = 1.0 #SigmoidAlpha = -0.5 #SigmoidBeta = 3.0 TimeThreshold = 100 StoppingValue = 100 seg.doSegment(tempinfile, tempoutfile, self.seedX, self.seedY, self.Sigma, self.SigmoidAlpha, self.SigmoidBeta, TimeThreshold, StoppingValue) print 'Segmentation done!' #OutputPixelType = itk.UC #OutputImageType = itk.Image[OutputPixelType, 2] #WriterType = itk.ImageFileWriter[ OutputImageType ] #writer = WriterType.New() #writer.SetFileName('out.tiff') #writer.SetInput( segm_out ) #writer.Update() #print 'File Output done' buffer = open(tempoutfile, 'r') #buffer= cStringIO.StringIO(tempoutfile) print ' posting the output to the server ..' file = [('upload', tempoutfile, buffer.read())] resp, content = post_files( self.client_server + '/bisquik/upload_raw_image', file, [], userpass=self.userpass, ) log.debug("RESP: " + str(content)) self.image_out_url = str(content)
def processImage(self): log.debug("IMAGE: " + self.image.z + ',' + self.image.t + ',' + self.image.ch) print 'In process image' if int(self.image.z) == 1 and int(self.image.t) == 1 and (int(self.image.ch) ==1 or int(self.image.ch) == 3): # read image from Bisque system resp, content = request(self.image.src + '?format=tiff', "GET", userpass = self.userpass ) # convert stream into Image im = cStringIO.StringIO(content) img = Image.open(im) log.debug("IMAGE: " + str(img.format) + ',' + str(img.size) + ',' + str(img.mode)) ''' IMAGE PROCESSING ''' # convert color image into grayscale image grayimg = ImageOps.grayscale(img) # convert Image into numpy array in_im = asarray(grayimg) # normalize image norm_im = self.normalizeImage(in_im) # set the threshold value thNorm = double((double(self.thValue)/100.0)) # threshold image with thNorm value th_im = norm_im < thNorm; # label image with 8conn structure = [[1,1,1], [1,1,1], [1,1,1]] th_im = binary_erosion(~th_im,structure) label_tuple = label(th_im,structure) #(data, dtype, number of labels) label_im = label_tuple[0]-1 # wathershed wh_im = watershed_ift(in_im, label_im) # convert numpy array into Image img_out = Image.fromarray(wh_im.astype('uint8')) ''' IMAGE PROCESSING ''' # convert Image into stream buffer = StringIO.StringIO() img_out.save(buffer, 'TIFF') # upload image into Bisque system buffer.seek(0) buffer.name = 'file.tif' fields = { 'file' : buffer } resp, content = post_files (self.client_server + '/bisquik/upload_images', fields=fields, userpass = self.userpass,) log.debug("RESP: " + str(content)) self.image_out_url = str(content)