def directInvokeAlgorithm(self,vals): print('oooo invoking: butterworthFilter with vals', vals); input = self.inputs['input']; try: inp = input; out = None; if (vals['type'] == "low" or vals['type'] == "band"): out = libbis.butterworthFilterWASM(input, { "type": "low", "cutoff": vals['low'], "samplerate": vals['tr'] }, self.parseBoolean(vals['debug'])); if (vals['type'] == "low"): self.outputs['output']=bis_objects.bisMatrix() self.outputs['output'].create(out); return True inp = out; out= libbis.butterworthFilterWASM(inp, { "type": "high", "cutoff": vals['high'], "samplerate": vals['tr'], }, self.parseBoolean(vals['debug'])); self.outputs['output']=bis_objects.bisMatrix(); self.outputs['output'].create(out); except: return False return True
def directInvokeAlgorithm(self, vals): print('oooo invoking: computeROI with vals', vals) input = self.inputs['input'] roi = self.inputs['roi'] if (roi.hasSameOrientation(input, 'ROI', 'Input', True) == False): return False print('oooo') print('oooo Input=', input.getDescription()) print('oooo ROI=', roi.getDescription()) try: out = libbis.computeROIWASM( input, roi, {'storecentroids': self.parseBoolean(vals['storecentroids'])}, self.parseBoolean(vals['debug'])) a = out.shape if (a[0] * a[1] < 1): print(' ----- Bad Input Images') return False self.outputs['output'] = bis_objects.bisMatrix() self.outputs['output'].create(out) except: e = sys.exc_info()[0] print('---- Failed to invoke algorithm ' + str(e)) return False return True
def loadSingleInput(self, key, filename, objecttype): if (objecttype == 'image'): self.inputs[key] = bis_objects.bisImage() elif (objecttype == 'matrix' or objecttype == 'vector'): self.inputs[key] = bis_objects.bisMatrix() elif (objecttype == 'transformation' or objecttype == 'transform'): self.inputs[key] = bis_objects.loadTransformation(filename) if (self.inputs[key] == None): return False return True try: ok = self.inputs[key].load(filename) if (ok != False): sz = self.inputs[key].data_array.shape if (sz[1] == 1 and objecttype == 'vector'): tmp = self.inputs[key] self.inputs[key] = bis_objects.bisVector() self.inputs[key].create(tmp.data_array.flatten()) ok = self.inputs[key] except: return False print('++++ \t loaded ' + objecttype + ' ' + key + ' from ' + filename) if (ok != False): return True return ok
def directInvokeAlgorithm(self, vals): print('oooo invoking: computeCorrelation with vals', (vals)) input = self.inputs['input'] weight = self.inputs['weight'] try: out = libbis.computeCorrelationMatrixWASM( input, weight, {"toz": self.parseBoolean(vals['zscore'])}, self.parseBoolean(vals['debug'])) self.outputs['output'] = bis_objects.bisMatrix() self.outputs['output'].create(out) except: print('---- Failed to invoke algorithm') return False return True
def directInvokeAlgorithm(self, vals): print('oooo invoking: computeROI with vals', vals) input = self.inputs['input'] roi = self.inputs['roi'] try: out = libbis.computeROIWASM(input, roi, self.parseBoolean(vals['debug'])) self.outputs['output'] = bis_objects.bisMatrix() self.outputs['output'].create(out) except: print('---- Failed to invoke algorithm') return False return True
def directInvokeAlgorithm(self,vals): print('oooo invoking: regressGlobal with vals', (vals)); input = self.inputs['input']; weight=self.inputs['weight']; try: out = libbis.weightedRegressGlobalSignalWASM(input, weight, self.parseBoolean(vals['debug'])); self.outputs['output']=bis_objects.bisMatrix(); self.outputs['output'].create(out); except: print('---- Failed to invoke algorithm'); return False return True;
def deserialize_object(ptr, datatype='', offset=0, first_input=0): if datatype == '': datatype = getNameFromMagicCode(magic_code) if datatype == 'String': output = bis.bisVector() output.deserializeWasm(ptr, offset) return output.getString() if datatype == 'Matrix': output = bis.bisMatrix() output.deserializeWasm(ptr, offset) return output.get_data() if datatype == 'Vector': output = bis.bisVector() output.deserializeWasm(ptr, offset) return output.get_data() if datatype == 'bisComboTransformation': output = bis.bisComboTransformation() output.deserializeWasm(ptr, offset) return output if datatype == 'bisGridTransformation': output = bis.bisGridTransformation() output.deserializeWasm(ptr, offset) return output if datatype == 'bisLinearTransformation': output = bis.bisLinearTransformation() output.deserializeWasm(ptr, offset) return output.get_data() if datatype != 'bisImage': raise ValueError('Unknown datatype ', datatype) # Image from here output = bis.bisImage() output.deserializeWasm(ptr, offset) if type(first_input) is bis.bisImage: output.affine = first_input.affine return output
def processTestResult(toolname, resultFile, test_target, test_type, test_threshold, test_comparison): threshold = test_threshold if (threshold == None): threshold = 0.01 comparison = test_comparison if (comparison == None): comparison = "maxabs" if (test_type == 'image'): if (comparison != "maxabs" and comparison != "ssd"): comparison = "cc" if (test_type == 'matrix' or test_type == "matrixtransform" or test_type == "gridtransform"): if (comparison != "maxabs"): comparison = "ssd" print( '====\n==================================================================\n====' ) print('==== comparing ', test_type, ' using ', comparison, ' and threshold=', threshold, '.\n====') print('==== files=', resultFile, test_target) if (test_type == "image"): out = bis_objects.bisImage() if (out.load(resultFile) != False): gold = bis_objects.bisImage() if (gold.load(test_target) != False): diff = 0 if (comparison == 'cc'): diff = -computeCC(out.get_data(), gold.get_data()) threshold = -threshold elif comparison == 'ssd': diff = computeNorm2(out.get_data(), gold.get_data()) else: diff = maxabsdiff(gold.get_data(), out.get_data()) return printResult(diff, threshold, toolname, test_type) else: print('---- Failed to load gold standard image') return False else: print('---- Failed to load input image') return False elif (test_type == "matrix"): out = bis_objects.bisMatrix() if (out.load(resultFile) != False): gold = bis_objects.bisMatrix() if (gold.load(test_target) != False): print('out ', resultFile, ' dims=', out.data_array.shape) print('gold ', test_target, ' dims=', gold.data_array.shape) if (comparison == 'maxabs'): diff = maxabsdiff(gold.data_array, out.data_array) else: diff = computeNorm2(gold.data_array, out.data_array) return printResult(diff, threshold, toolname, test_type) else: return False else: return False elif (test_type == "matrixtransform"): out = bis_objects.bisLinearTransformation() if (out.load(resultFile) != False): gold = bis_objects.bisLinearTransformation() if (gold.load(test_target) != False): print('out ', resultFile, ' dims=', out.data_array.shape) print('gold ', test_target, ' dims=', gold.data_array.shape) if (comparison == 'maxabs'): diff = maxabsdiff(gold.data_array, out.data_array) else: diff = computeNorm2(gold.data_array, out.data_array) return printResult(diff, threshold, toolname, test_type) else: return False else: return False elif (test_type == "gridtransform"): out = bis_objects.bisComboTransformation() if (out.load(resultFile) != False): print('out ', resultFile, ' dims=', out.grids[0].data_array.shape) gold = bis_objects.bisComboTransformation() if (gold.load(test_target) != False): print('gold ', test_target, ' dims=', gold.grids[0].data_array.shape) if (comparison == 'maxabs'): diff = maxabsdiff(gold.grids[0].data_array, out.grids[0].data_array) else: diff = computeNorm2(gold.grids[0].data_array, out.grids[0].data_array) return printResult(diff, threshold, toolname, test_type) else: return False else: return False print('---- Cannot compare type :', test_type) return False