def medianstack(filelist, ext=0, **options): """ Compute the median for a list of images. Usefull to elliminate cosmic rays from dark images Syntax: medianstack(filelist) return an image which is the median stack form the files in the current directory example: med = medianstack([dk1, dk2, dk3], 0) compute median for images dk1, dk2 and dk3 using extension 0 TODO: Check if filelist is a list of images o list of strings and then perform the computation accordingly """ #check if filelist is a list, if not raise error try: if (isinstance(filelist, list) and len(filelist) > 1): pass else: raise Exception except: print("Not a list or len < 2") return None #check if elements in filelist is Image or string if all([isinstance(i, Image) for i in filelist]): imagesdata = [i.get_data() for i in filelist] im = filelist[0].copy() im.filename = 'medianstack' im.data = np.median(imagesdata, axis=0) return im if all([isinstance(i, str) for i in filelist]): #copy first image on list to get same dim imagesdata = [Image(i, ext).get_data() for i in filelist] im = Image(filelist[0], ext) im.filename = 'medianstack' im.data = np.median(imagesdata, axis=0) return im elif all([isinstance(i, Path) for i in filelist]): #copy first image on list to get same dim imagesdata = [Image(i, ext).get_data() for i in filelist] im = Image(filelist[0], ext) im.filename = 'medianstack' im.data = np.median(imagesdata, axis=0) return im return None
def stdstack(filelist, ext=0, **options): """ Compute the standard deviation in z direction for a list of images. Syntax: stdstack(filelist) return an image which is the std pixel by pixel for the files in the list example: stdmap = stdstack([dk1, dk2, dk3,..,dkn], 0) compute median for images dk1, dk2, dk3 to dkn using extension 0 """ #check if filelist is a list, if not raise error try: if (isinstance(filelist, list) and len(filelist) > 1): pass else: raise Exception except: print("Not a list or len < 2") return None #check if elements in filelist are Images or string if all([isinstance(i, Image) for i in filelist]): imagesdata = [i.get_data() for i in filelist] im = filelist[0].copy() im.filename = 'stdstack' im.data = np.std(imagesdata, axis=0) return im #check if filelist are files names if all([isinstance(i, str) for i in filelist]): #copy first image on list to get same dim imagesdata = [Image(i, ext).get_data() for i in filelist] im = Image(filelist[0], ext) im.filename = 'stdstack' im.data = np.std(imagesdata, axis=0) return im elif all([isinstance(i, Path) for i in filelist]): #copy first image on list to get same dim imagesdata = [Image(i, ext).get_data() for i in filelist] im = Image(filelist[0], ext) im.filename = 'stdstack' im.data = np.std(imagesdata, axis=0) return im return None
def meanstack(filelist, ext=0, **options): """ Compute the mean for a list of images. Syntax: medianstack(filelist) return an image which is the median stack form the files in the current directory example: med = meanstack([dk1, dk2, dk3], 0) compute median for images dk1, dk2 and dk3 using extension 0 TODO: Check if filelist is a list of images o list of strings and then perform the computation accordingly """ #check if filelist is a list, if not raise error try: if (isinstance(filelist,list) and len(filelist)>1): pass else: raise Exception except: print("Not a list or len < 2") return None #check if elements in filelist is Image or string allimages = [isinstance(i,Image) for i in filelist] if all(allimages): imagesdata = [i.get_data() for i in filelist] im = filelist[0].copy() im.filename = 'meanstack' im.data=np.mean(imagesdata, axis = 0) return im #check if filelist are files names allfiles = [isinstance(i,str) for i in filelist] if all(allfiles): #copy first image on list to get same dim imagesdata = [Image(i,ext).get_data() for i in filelist] im = Image(filelist[0],ext) im.filename = 'meanstack' im.data=np.mean(imagesdata, axis = 0) return im return None
def stdstack(filelist, ext=0, **options): """ Compute the standard deviation in z direction for a list of images. Syntax: stdstack(filelist) return an image which is the std pixel by pixel for the files in the list example: stdmap = stdstack([dk1, dk2, dk3,..,dkn], 0) compute median for images dk1, dk2, dk3 to dkn using extension 0 """ #check if filelist is a list, if not raise error try: if (isinstance(filelist,list) and len(filelist)>1): pass else: raise Exception except: print("Not a list or len < 2") return None #check if elements in filelist are Images or string allimages = [isinstance(i,Image) for i in filelist] if all(allimages): imagesdata = [i.get_data() for i in filelist] im = filelist[0].copy() im.filename = 'stdstack' im.data=np.std(imagesdata, axis = 0) return im #check if filelist are files names allfiles = [isinstance(i,str) for i in filelist] if all(allfiles): #copy first image on list to get same dim imagesdata = [Image(i,ext).get_data() for i in filelist] im = Image(filelist[0],ext) im.filename = 'stdstack' im.data=np.std(imagesdata, axis = 0) return im return None