def run_onthisthread(self): """ Run the Zprojection This is not in run, so we can bypass run() if we don't want to start a new thread """ print 'zproject thread id', QtCore.QThread.currentThreadId() if os.path.isfile(self.zprojection_output) is False or self.force: print "Computing z-projection..." if len(self.imglist) < 1: self.emit(QtCore.SIGNAL('update(QString)'), "No recon images found!") reader = Imreader(self.imglist) try: im = reader.imread(self.imglist[0]) except HarpDataError as e: self.update.emit(e.message) # emit back to differnt thread. or... raise # reraise for autocrop, on same thread imdims = im.shape dtype = im.dtype # make a new list by removing every nth image sparse_filelist = sorted(self.imglist)[0::self.skip_num] print "performing z-projection on sparse file list" max_array = self.max_projection(sparse_filelist, imdims, dtype) imwrite(self.zprojection_output, max_array) self.emit(QtCore.SIGNAL('update(QString)'), "Z-projection finished")
def run_onthisthread(self): """ Run the Zprojection This is not in run, so we can bypass run() if we don't want to start a new thread """ print 'zproject thread id', QtCore.QThread.currentThreadId() if os.path.isfile(self.zprojection_output) is False or self.force: print "Computing z-projection..." if len(self.imglist) < 1: self.emit(QtCore.SIGNAL('update(QString)'), "No recon images found!") reader = Imreader(self.imglist) try: im = reader.imread(self.imglist[0]) except HarpDataError as e: self.update.emit( e.message) # emit back to differnt thread. or... raise # reraise for autocrop, on same thread imdims = im.shape dtype = im.dtype # make a new list by removing every nth image sparse_filelist = sorted(self.imglist)[0::self.skip_num] print "performing z-projection on sparse file list" max_array = self.max_projection(sparse_filelist, imdims, dtype) imwrite(self.zprojection_output, max_array) self.emit(QtCore.SIGNAL('update(QString)'), "Z-projection finished")
def run(self, auto=False): """ Perform a crop based on previously selected bounding box :return: """ # Get list of files #imglist = processing.getfilelist(self.in_dir) imglist = self.app_data.getfilelist(self.in_dir) if len(imglist) < 1: raise HarpDataError("no image files found in " + self.in_dir) if auto: cb = self.auto_bounding_box(imglist) #rearange as dims come in a differenbt order from the different methods cropbox = (cb[2], cb[3], cb[0], cb[1]) else: cropbox = self.calc_manual_crop() cropbox = [cropbox[1], cropbox[3], cropbox[0], cropbox[2]] # rearrange for numpy slicing first = True outpathslist = [] reader = Imreader(imglist) for count, file_ in enumerate(imglist): try: im = reader.imread(file_) except IOError as e: raise HarpDataError("failed to read {}".format(file_)) else: if im.shape[0] < 1 or im.shape[1] < 1: raise HarpDataError('Cannot read file, {}'.format(file_)) if first: dimcheck = im.shape first = False else: if im.shape != dimcheck: raise HarpDataError( "Input files have different shapes {} and {}".format( dimcheck, imglist[0], file_)) # try: # pass # #im[dimcheck] Check for indexing error as .shape is derived from header only if count % 20 == 0: if self.thread_terminate_flag.value == 1: raise HarpDataError('Cancelled') self.callback("Cropping: {0}/{1} images".format( count, str(len(imglist)))) filename = os.path.basename(file_) crop_out = os.path.join(self.out_dir, filename) try: imcrop = im[cropbox[0]:cropbox[1], cropbox[2]:cropbox[3]] except IndexError as e: raise HarpDataError( "Crop box out of range. Is {} corrupted?".format(filename)) imwrite(crop_out, imcrop) outpathslist.append(crop_out) self.callback("success") return outpathslist
def run(self, auto=False): """ Perform a crop based on previously selected bounding box :return: """ # Get list of files #imglist = processing.getfilelist(self.in_dir) imglist = self.app_data.getfilelist(self.in_dir) if len(imglist) < 1: raise HarpDataError("no image files found in " + self.in_dir) if auto: cb = self.auto_bounding_box(imglist) #rearange as dims come in a differenbt order from the different methods cropbox = (cb[2], cb[3], cb[0], cb[1]) else: cropbox = self.calc_manual_crop() cropbox = [cropbox[1], cropbox[3], cropbox[0], cropbox[2]] # rearrange for numpy slicing first = True outpathslist = [] reader = Imreader(imglist) for count, file_ in enumerate(imglist): try: im = reader.imread(file_) except IOError as e: raise HarpDataError("failed to read {}".format(file_)) else: if im.shape[0] < 1 or im.shape[1] < 1: raise HarpDataError('Cannot read file, {}'.format(file_)) if first: dimcheck = im.shape first = False else: if im.shape != dimcheck: raise HarpDataError("Input files have different shapes {} and {}". format(dimcheck, imglist[0], file_)) # try: # pass # #im[dimcheck] Check for indexing error as .shape is derived from header only if count % 20 == 0: if self.thread_terminate_flag.value == 1: raise HarpDataError('Cancelled') self.callback( "Cropping: {0}/{1} images".format(count, str(len(imglist)))) filename = os.path.basename(file_) crop_out = os.path.join(self.out_dir, filename) try: imcrop = im[cropbox[0]:cropbox[1], cropbox[2]: cropbox[3]] except IndexError as e: raise HarpDataError("Crop box out of range. Is {} corrupted?".format(filename)) imwrite(crop_out, imcrop) outpathslist.append(crop_out) self.callback("success") return outpathslist