def run(self): Hname = utils.getFilename("Select affine transformation matrix", [('npy files', '.npy')]) H = np.load(Hname) text = "Select files for affine transformation" filenames = utils.getFilenames(text, types=[], initialdir=os.path.split(Hname)[0]) for filename in filenames: print( time.strftime("%Y-%m-%d %H:%M:%S") + ' Transforming stack ' + os.path.split(filename)[1]) ext = os.path.splitext(filename)[1] filename2 = utils.insertSuffix(filename, '_corrected') if ext == '.hdf5': with hdf.File(filename, 'r') as f0, \ hdf.File(filename2, 'w') as f1: dat0 = f0['data'] xlim, ylim, cropShape = get_affine_shapes(dat0.shape, H) print(dat0.shape) dat1 = self.mpStack(dat0, xlim, ylim, H) # Store f1.create_dataset(name='data', data=dat1) # f1['data'][:, -cropShape[0]:, :] = im1c elif ext in ['.tiff', '.tif']: with tiff.TiffFile(filename) as tt: dat0 = tt.asarray() if len(dat0.shape) > 2: results = get_affine_shapes(dat0.shape, H) xlim, ylim, cropShape = results dat1 = self.mpStack(dat0, xlim, ylim, H) tiff.imsave(filename2, dat1) else: sh0 = np.array( [0.5 * dat0.shape[0] - 5, dat0.shape[1]]) sh0 = sh0.astype(np.int) tiff.imsave(utils.insertSuffix(filename, '_ch0'), dat0[:sh0[0], :]) tiff.imsave(utils.insertSuffix(filename, '_ch1'), h_affine_transform(dat0[-sh0[0]:, :], H)) print(time.strftime("%Y-%m-%d %H:%M:%S") + ' done') self.finished.emit()
def split_two_colors(files): for name in files: with hdf.File(name, 'r') as ff: print(name) center = int(0.5*ff['data'].value.shape[1]) with hdf.File(utils.insertSuffix(name, '_ch0'), 'w') as ff0: ff0['data'] = ff['data'][:, center - 5 - 128:center - 5, :] with hdf.File(utils.insertSuffix(name, '_ch1'), 'w') as ff1: ff1['data'] = ff['data'][:, center + 5:center + 5 + 128, :]
def getUniqueName(name): n = 1 while os.path.exists(name): if n > 1: name = name.replace('_{}.'.format(n - 1), '_{}.'.format(n)) else: name = utils.insertSuffix(name, '_{}'.format(n)) n += 1 return name
def run(self): txt = "Select files for background sustraction" initialdir = self.main.recWidget.folderEdit.text() filenames = utils.getFilenames(txt, types=[], initialdir=initialdir) print( time.strftime("%Y-%m-%d %H:%M:%S") + ' Background subtraction started') for filename in filenames: print( time.strftime("%Y-%m-%d %H:%M:%S") + ' Processing stack ' + os.path.split(filename)[1]) ext = os.path.splitext(filename)[1] filename2 = utils.insertSuffix(filename, '_subtracted') if ext == '.hdf5': with hdf.File(filename, 'r') as f0, \ hdf.File(filename2, 'w') as f1: self.data = f0['data'].value if len(self.data) > self.window: dataSub = self.mpSubtract() f1.create_dataset(name='data', data=dataSub) else: print('Stack shorter than filter window --> ignore') elif ext in ['.tiff', '.tif']: with tiff.TiffFile(filename) as tt: self.data = tt.asarray() if len(self.data) > self.window: dataSub = self.mpSubtract() tiff.imsave(filename2, dataSub) else: print('Stack shorter than filter window --> ignore') print( time.strftime("%Y-%m-%d %H:%M:%S") + ' Background subtraction finished') self.finished.emit()
def run(self): txt = "Select files for background sustraction" initialdir = self.main.recWidget.folderEdit.text() filenames = utils.getFilenames(txt, types=[], initialdir=initialdir) print(time.strftime("%Y-%m-%d %H:%M:%S") + ' Background subtraction started') for filename in filenames: print(time.strftime("%Y-%m-%d %H:%M:%S") + ' Processing stack ' + os.path.split(filename)[1]) ext = os.path.splitext(filename)[1] filename2 = utils.insertSuffix(filename, '_subtracted') if ext == '.hdf5': with hdf.File(filename, 'r') as f0, \ hdf.File(filename2, 'w') as f1: self.data = f0['data'].value if len(self.data) > self.window: dataSub = self.mpSubtract() f1.create_dataset(name='data', data=dataSub) else: print('Stack shorter than filter window --> ignore') elif ext in ['.tiff', '.tif']: with tiff.TiffFile(filename) as tt: self.data = tt.asarray() if len(self.data) > self.window: dataSub = self.mpSubtract() tiff.imsave(filename2, dataSub) else: print('Stack shorter than filter window --> ignore') print(time.strftime("%Y-%m-%d %H:%M:%S") + ' Background subtraction finished') self.finished.emit()