def import_images(files, outfile, params): proc = TiffProcessor(files[0], None, params.seg_params, params.channels, params.gsize) writer = HdfWriter(outfile) colors = [params.colors[c] for c in params.channels.values()] writer.setupFile(len(files), params.channels, colors) writer.saveSettings(params.seg_params, params.feature_groups, params.channels.values(), params.colors) pool = Pool(processes=8)#, initializer=initfunc, initargs=("Hello world!", )) fprm = zip(files, len(files)*[params]) results = list() for fp in fprm: #import pdb; pdb.set_trace() results.append(pool.apply_async(process_image, fp, callback=callback)) pool.close() pool.join() for res, file_ in zip(results, files): _, image, image_objects, feature_names = res.get() # reconstruct the ObjectDict objects = ObjectDict("multicolor") objects.feature_names = feature_names for obj in image_objects: objects[obj.label] = obj writer.saveData(objects, image, None, file_) writer.flush()
def saveData(self): # be carefull save Data is runs in a different thread # (callback of map_async) self.pool.close() self.pool.join() self.parent().onFileClose() writer = HdfWriter(self.dataFile.text()) try: channels = self.cbar.checkedChannels() proc = TiffProcessor( self._files[0], self._regex, self.segdlg.segmentationParams(), self.cbar.checkedChannels() ) colors = [self.cbar.colors[ch] for ch in channels.values()] writer.setupFile(len(self._files), channels, colors) writer.saveSettings( self.segdlg.segmentationParams(), self.segdlg.featureGroups(), channels.values(), self.cbar.colors ) for i, res_ in enumerate(self.results): res = res_.get() file_, image, image_objects, feature_names = res # reconstruct the ObjectDict objects = ObjectDict("multicolor") objects.feature_names = feature_names for obj in image_objects: objects[obj.label] = obj writer.saveData(objects, image, None, file_.file) self.incrementProgress() writer.flush() finally: writer.close() self.finished.emit()
def __call__(self): self.started.emit() self.progressSetRange.emit(0, len(self.files)) writer = HdfWriter(self.outfile) colors = [self.colors[ch] for ch in self.channels.values()] writer.setupFile(self.metadata.n_images, self.channels, colors) writer.saveSettings(self.seg_params, self.feature_groups, self.channels.values(), self.colors) try: gsize = self.seg_params.values()[0].gallery_size for i, (file_, treatment) in enumerate(self.files.iteritems()): self.progressUpdate.emit(i + 1) self.interruption_point() self.thread().msleep(self.PYDELAY) mp = LsmProcessor(file_, self.seg_params, self.channels, gsize, treatment) # first channel for primary segementation mp.segmentation() mp.calculateFeatures(self.feature_groups) objects = mp.objects # saveData ignores empty objects image = mp.image[:, :, :, self.channels.keys()] writer.saveData(objects, image, treatment) self.contourImage.emit(tuple(mp.iterQImages()), objects.contours) self.progressSetRange.emit(0, 0) self.progressUpdate.emit(-1) writer.flush() self.finished.emit() except AbortQWorker: pass except HdfError as e: self.error.emit(e) traceback.print_exc() raise except Exception as e: self.error.emit(e) traceback.print_exc() raise finally: writer.close()
def __call__(self): self.started.emit() self.progressSetRange.emit(0, len(self.files)) writer = HdfWriter(self.outfile) colors = [self.colors[ch] for ch in self.channels.values()] writer.setupFile(self.metadata.n_images, self.channels, colors) writer.saveSettings(self.seg_params, self.feature_groups, self.channels.values(), self.colors) try: gsize = self.seg_params.values()[0].gallery_size for i, (file_, treatment) in enumerate(self.files.iteritems()): self.progressUpdate.emit(i+1) self.interruption_point() self.thread().msleep(self.PYDELAY) mp = LsmProcessor(file_, self.seg_params, self.channels, gsize, treatment) # first channel for primary segementation mp.segmentation() mp.calculateFeatures(self.feature_groups) objects = mp.objects # saveData ignores empty objects image = mp.image[:, :, :, self.channels.keys()] writer.saveData(objects, image, treatment) self.contourImage.emit(tuple(mp.iterQImages()), objects.contours) self.progressSetRange.emit(0, 0) self.progressUpdate.emit(-1) writer.flush() self.finished.emit() except AbortQWorker: pass except HdfError as e: self.error.emit(e) traceback.print_exc() raise except Exception as e: self.error.emit(e) traceback.print_exc() raise finally: writer.close()