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 postTag(self,parent,tag): req = etree.Element ('request') etree.SubElement (req, 'tag', name=str(tag.name), value=str(tag.value), type='string') log.debug("REQ: " + etree.tostring(req)) resp, content = request(parent.uri, "POST", body = etree.tostring(req), headers={'content-type':'text/xml' }, userpass = self.userpass ) log.debug("RESP: " + str(content)) return resp
def loadImage(self, url): resp, content = request(url, userpass = self.userpass) log.debug ('itkGeodesicSegmentationPY - response: ' + str(content) + '||||||||||' +url) response = etree.XML(content) image = parseXml(root = response, factory = BQNodeFactory) log.debug("GOT " + str(image.uri)) return image
def loadImage(self, url): resp, content = request(url) log.debug('itkModulePY - response: ' + str(content) + '||||||||||' + url) response = etree.XML(content) image = parseXml(root=response, factory=BQNodeFactory) log.debug("GOT " + str(image.uri)) return image
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)
def main(self): print 'Running in main' client_server = sys.argv[1] image_url = sys.argv[2] user = '******' password = '******' self.userpass = (user, password) seedX = [81, 99, 56, 40] seedY = [114, 114, 92, 90] Sigma = [1.0, 1.0, 1.0, 1.0] SigmoidAlpha = [-0.5, -0.5, -0.3, -0.3] SigmoidBeta = [3.0, 3.0, 2.0, 2.0] requesturl = client_server + '/ms/' #run all the four segmentation processes sequentially for i in range(0, len(seedX)): # Initiate the mex response = self.createXML(client_server, image_url, seedX[i], seedY[i], Sigma[i], SigmoidAlpha[i], SigmoidBeta[i]) resp, content = xmlrequest(requesturl, method="POST", body=etree.tostring(response), userpass=self.userpass) #print 'RESPONSE = ', str(resp) #print 'CONTENT = ',str(content) #print 'CONTENT LENGTH = ',len(content) # Check mex status #mex = etree.parse(content) #print '\n\n parsing \n\n' mex = etree.parse(StringIO.StringIO(content)) uri = mex.getroot().get('uri') #print '\nURI = ' ,str(uri) while 1: resp, content = request(uri, userpass=self.userpass) #print "###CONTENT = ",str(content) mex = etree.parse(StringIO.StringIO(content)) if mex.getroot()[0].get('status') == 'FINISHED': print 'Finished' break elif mex.getroot()[0].get('status') == 'FAILURE': print 'Failure' break #else: # print '### Waiting..' # START COMMENT # decide on the tag name to search #if seedX in range(78,83): # tagName= "Left_Ventricle_Mask" #elif seedX in range(97,101): # tagName = "Right_Ventricle_Mask" #elif seedX in range(54,58): # tagName = "White_Matter_Mask" #elif seedX in range(38,42): # tagName = "Grey_Matter_Mask" #else: # tagName = "Unknown_Region_Mask" # Now the tag is created- search for the tag in the image url-tag #resp, content = request(image_url, userpass=self.userpass) #print 'image url CONTENT = ',str(content) #tag = etree.parse(StringIO.StringIO(content)) #tag_url = tag.getroot()[0][0].get('uri') #request for the tag values again #resp, content = request(tag_url , userpass=self.userpass) #print 'image url CONTENT = ',str(content) #tag = etree.parse(StringIO.StringIO(content)) #tag_root = tag.getroot() #now parse the xml #i = 0; #while tag_root[i] != None: # name = tag_root[i].get('name') # if(name == tagName): # break # else: # i = i+1 #mask_url = tag_root[i].get('value') #if mask_url=='': # print '\nERROR: mask_url not found' #print '\n\n', mask_url #time.sleep(5) #END COMMENT tagName = [ 'Left_Ventricle_Mask', 'Right_Ventricle_Mask', 'White_Matter_Mask', 'Grey_Matter_Mask' ] requesturl = client_server + '/ms/' #Start processing for program 2 for i in range(0, len(tagName)): response = self.createXML2(client_server, image_url, tagName[i]) resp, content = xmlrequest(requesturl, method="POST", body=etree.tostring(response), userpass=self.userpass) #print 'RESPONSE = ', str(resp) #print 'CONTENT = ',str(content) #print 'CONTENT LENGTH = ',len(content) mex = etree.parse(StringIO.StringIO(content)) uri = mex.getroot().get('uri') #print '\nURI = ' ,str(uri) condCount = 0 while 1: resp, content = request(uri, userpass=self.userpass) mex = etree.parse(StringIO.StringIO(content)) if mex.getroot()[0].get('status') == 'FINISHED': print ' Finished module 2' break elif mex.getroot()[0].get('status') == 'FAILURE': if condCount < 3: print 'Failure module 2 == Retrying for a free engine', condCount print 'Sleeping for 5 seconds' time.sleep(5) resp, content = xmlrequest( requesturl, method="POST", body=etree.tostring(response), userpass=self.userpass) mex = etree.parse(StringIO.StringIO(content)) uri = mex.getroot().get('uri') condCount += 1 else: print 'Failure module 2' break