Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
    def objects(self):
        if self._objects is None:
            odict = ObjectDict("multicolor")
            for i, (name, container) in enumerate(self._containers.iteritems()):
                for label, cobj in container.getObjects().iteritems():
                    obj = ImageObject(
                        name, cobj, container.getCrackCoordinates(label),
                        self.treatment, label)

                    if odict.has_key(label):
                        odict.concatenate(name, label, obj)
                    else:
                        # mulitchannel gallery image
                        obj.gallery_image = self._gallery_image(
                            obj.center, gallery_size=self.gsize)
                        odict[label] = obj

                # set feature names extend with a prefix
                try:
                    cn = name.split()[1]
                    odict.feature_names.extend(
                        ["ch%s-%s" %(cn, n) for n in obj.feature_names])
                except UnboundLocalError as e:
                    # empty image has no objects
                    pass

            removed = odict.remove_incomplete()
            if len(removed) > 0:
                warnings.warn("%d objects have been removed" %len(removed))
            self._objects = odict
        return self._objects
Ejemplo n.º 4
0
    def objects(self):
        if self._objects is None:
            odict = ObjectDict("multicolor")
            for i, (name,
                    container) in enumerate(self._containers.iteritems()):
                for label, cobj in container.getObjects().iteritems():
                    obj = ImageObject(name, cobj,
                                      container.getCrackCoordinates(label),
                                      self.treatment, label)

                    if odict.has_key(label):
                        odict.concatenate(name, label, obj)
                    else:
                        # mulitchannel gallery image
                        obj.gallery_image = self._gallery_image(
                            obj.center, gallery_size=self.gsize)
                        odict[label] = obj

                # set feature names extend with a prefix
                try:
                    cn = name.split()[1]
                    odict.feature_names.extend(
                        ["ch%s-%s" % (cn, n) for n in obj.feature_names])
                except UnboundLocalError as e:
                    # empty image has no objects
                    pass

            removed = odict.remove_incomplete()
            if len(removed) > 0:
                warnings.warn("%d objects have been removed" % len(removed))
            self._objects = odict
        return self._objects