def RUN(code, *, update=False, visual=False): ## Update query ## if (update): # Create a new microscope # scope = Microscope(code) # No saving necessary here, as the image exists in \Images and the aperture and kernel exist in their respective folders else: # Load in what we already have # scope = Microscope() scope.code = code if (OP._CheckFile(code + str(FMT.TIF), OP.FOLD_IMG)): # Experimental # scope.img = OP._LoadMov('%s' % (code), fold=OP.FOLD_IMG) elif (OP._CheckFile(code + str(FMT.TIF), OP.FOLD_SIM)): # Simulation # scope.img = OP._LoadMov('%s' % (code), fold=OP.FOLD_SIM) else: # Override - make a fake image # scope.img = np.zeros([USER.SIM_FRAMES, 1, *USER.CHIP]) #raise FileNotFoundError('The specified image or simulation code was not found') scope.apr, scope.ker = scope.SimLoad(sz=np.shape(scope.img)[2:]) ## Visualization query ## if (visual): VIS._VisImg(scope.img[0, 0, :, :, ], 1000) VIS._VisImg(scope.ker[0, 0, :, :, ], 100) VIS._VisImg(scope.ker[0, (USER.KER_Z) // 4, :, :, ], 550) VIS._VisImg(scope.ker[0, (2 * USER.KER_Z) // 4, :, :, ], 550, 550) VIS._VisImg(scope.ker[0, (3 * USER.KER_Z) // 4, :, :, ], 100, 550) plt.pause(0.1) plt.show() pass # TODO # ## Output ## return scope
def __init__(self, code=None, *fxns, vis=False, blur=None): ## Initialization ## self.fxn_rot = _FxnRot(USER.KER_TYPE, USER.KER_Z > 1, USER.KER_T > 1) self.fxn_sep = _FxnSep(USER.KER_TYPE, USER.KER_Z > 1, USER.KER_T > 1) self.fxn_str = _FxnStr(USER.KER_TYPE, USER.KER_Z > 1, USER.KER_T > 1) # Check if we're even going to be doing anything # self.code = code if (code is None): return # Do it manually # ## Image ## if (USER.SIM_IMG or len(fxns) > 0): # Simulate the aperture and kernel if needed # apr, ker = self.SimLoad() # Simulate the image (this simulates the appropriate aperture and kernel) # img, mot = self.SimImage((USER.CHIP[1], USER.CHIP[0]), apr, *fxns, blur=blur) else: # Check if the code has a `.tif` at the end, and if so, remove it # if (code[-4:] == '.tif'): code = code[:-4] # Check if an image or simulation exists and load it (Assumes [F, Z, Y, X]) # if (OP._CheckFile(code + str(FMT.TIF), OP.FOLD_IMG)): # Experimental # img = OP._LoadMov(code, OP.FOLD_IMG) elif (OP._CheckFile(code + str(FMT.TIF), OP.FOLD_SIM)): # Simulation # img = OP._LoadMov(code, OP.FOLD_SIM) else: # Oops! # raise FileNotFoundError( 'The specified image or simulation code was not found') sz = np.shape(img)[2:] # Get the Y-X dimensions # # Simulate the aperture and kernel, if need be # apr, ker = self.SimLoad(sz) # Since we have no idea what the actual motion is, leave it blank # mot = None # Dump into the object # self.apr = apr self.ker = ker self.img = img self.mot = mot
def RUN(scope, *, code='', update=False, visual=False): ## Update query ## if (update or not OP._CheckFile('%s\\%s_prep.tif' % (code, code))): # Pre-process the movie and the kernel, obtaining the local threshold # img_, ker_, eps_ = _Preprocess2(code, scope.img, scope.ker) # Ensure that all values are non-negative # if (USER.KER_T > 1): img_ = np.maximum(img_, 0) ker_ = np.maximum(ker_, 0) eps_ = np.maximum(eps_, 0) # Save the processed image, kernel, and local threshold # OP._SaveMov(img_, '%s\\%s_prep' % (code, code)) # Processed Movie # OP._SaveKer(ker_, '%s\\%s_ker' % (code, code)) # Processed Kernel # OP._SaveMov(eps_, '%s\\%s_eps' % (code, code)) # Local Threshold # else: # Check if the movies exist # if (OP._CheckFile('%s\\%s_prep.tif' % (code, code))): # Load the processed image, kernel, and local threshold # img_ = OP._LoadMov('%s\\%s_prep' % (code, code)) # Processed Movie # ker_ = OP._LoadKer('%s\\%s_ker' % (code, code)) # Processed Kernel # eps_ = OP._LoadMov('%s\\%s_eps' % (code, code)) # Local Threshold # else: # Just stuff some zeros in there for now # img_ = np.zeros_like(scope.img) ker_ = np.zeros_like(scope.ker) eps_ = np.zeros_like(scope.img) ## Visualization query ## if (visual): f = 0 tru = OP._LoadTruth(code) pts = np.zeros([0, 3]) for p in range(len(tru)): if (f in tru[p].frm): idx = np.nonzero(f == tru[p].frm)[0] pts = np.concatenate((pts, tru[p].res[idx, :]), axis=0) # Movie # VIS._VisImg(img_[f, 0, :, :], 550, 50, pts) # Kernel # if ((USER.KER_Z > 1) and (USER.KER_T == 1)): VIS._VisImg(ker_[0, 0, :, :], 100, 50) VIS._VisImg(ker_[0, (USER.KER_Z) // 4, :, :], 100, 550) VIS._VisImg(ker_[0, (2 * USER.KER_Z) // 4, :, :], 550, 550) VIS._VisImg(ker_[0, (3 * USER.KER_Z) // 4, :, :], 1000, 550) VIS._VisImg(ker_[0, -1, :, :], 1000, 50) elif ((USER.KER_Z == 1) and (USER.KER_T > 1)): VIS._VisImg(ker_[0, 0, :, :], 100, 50) VIS._VisImg(ker_[(USER.KER_T) // 4, 0, :, :], 100, 550) VIS._VisImg(ker_[(2 * USER.KER_T) // 4, 0, :, :], 550, 550) VIS._VisImg(ker_[(3 * USER.KER_T) // 4, 0, :, :], 1000, 550) VIS._VisImg(ker_[-1, 0, :, :], 1000, 50) # Local Threshold # VIS._VisImg(eps_[f, 0, :, :], 1450, 50) VIS._VisImg(((img_ - eps_) * (img_ > eps_))[f, 0, :, :], 1450, 550, pts) plt.show() ## Output ## return img_, ker_, eps_