Пример #1
0
    def run(self, workspace):
        statistics = []
        m = workspace.measurements
        assert isinstance(m, cpmeas.Measurements)
        #
        # Hack: if LoadSingleImage is first, no paths are populated
        #
        if self.file_wants_images(self.file_settings[0]):
            m_path = "_".join((C_PATH_NAME, self.file_settings[0].image_name.value))
        else:
            m_path = "_".join((C_OBJECTS_PATH_NAME, self.file_settings[0].objects_name.value))
        if m.get_current_image_measurement(m_path) is None:
            self.prepare_run(workspace)

        image_set = workspace.image_set
        for file_setting in self.file_settings:
            wants_images = self.file_wants_images(file_setting)
            image_name = file_setting.image_name.value if wants_images else file_setting.objects_name.value
            m_path, m_file, m_md5_digest, m_scaling, m_height, m_width = [
                "_".join((c, image_name))
                for c in (
                    C_PATH_NAME if wants_images else C_OBJECTS_PATH_NAME,
                    C_FILE_NAME if wants_images else C_OBJECTS_FILE_NAME,
                    C_MD5_DIGEST,
                    C_SCALING,
                    C_HEIGHT,
                    C_WIDTH,
                )
            ]
            pathname = m.get_current_image_measurement(m_path)
            filename = m.get_current_image_measurement(m_file)
            rescale = wants_images and file_setting.rescale.value

            provider = LoadImagesImageProvider(image_name, pathname, filename, rescale)
            image = provider.provide_image(image_set)
            pixel_data = image.pixel_data
            if wants_images:
                md5 = provider.get_md5_hash(m)
                m.add_image_measurement("_".join((C_MD5_DIGEST, image_name)), md5)
                m.add_image_measurement("_".join((C_SCALING, image_name)), image.scale)
                m.add_image_measurement("_".join((C_HEIGHT, image_name)), int(pixel_data.shape[0]))
                m.add_image_measurement("_".join((C_WIDTH, image_name)), int(pixel_data.shape[1]))
                image_set.providers.append(provider)
            else:
                #
                # Turn image into objects
                #
                labels = convert_image_to_objects(pixel_data)
                objects = cpo.Objects()
                objects.segmented = labels
                object_set = workspace.object_set
                assert isinstance(object_set, cpo.ObjectSet)
                object_set.add_objects(objects, image_name)
                add_object_count_measurements(m, image_name, objects.count)
                add_object_location_measurements(m, image_name, labels)
                #
                # Add outlines if appropriate
                #
                if file_setting.wants_outlines:
                    outlines = centrosome.outline.outline(labels)
                    outline_image = cpi.Image(outlines.astype(bool))
                    workspace.image_set.add(file_setting.outlines_name.value, outline_image)
            statistics += [(image_name, filename)]
        workspace.display_data.col_labels = ("Image name", "File")
        workspace.display_data.statistics = statistics
Пример #2
0
    def run(self, workspace):
        statistics = []
        m = workspace.measurements
        assert isinstance(m, cpmeas.Measurements)
        #
        # Hack: if LoadSingleImage is first, no paths are populated
        #
        if self.file_wants_images(self.file_settings[0]):
            m_path = "_".join(
                (C_PATH_NAME, self.file_settings[0].image_name.value))
        else:
            m_path = "_".join((C_OBJECTS_PATH_NAME,
                               self.file_settings[0].objects_name.value))
        if m.get_current_image_measurement(m_path) is None:
            self.prepare_run(workspace)

        image_set = workspace.image_set
        for file_setting in self.file_settings:
            wants_images = self.file_wants_images(file_setting)
            image_name = file_setting.image_name.value if wants_images else \
                file_setting.objects_name.value
            m_path, m_file, m_md5_digest, m_scaling, m_height, m_width = [
                "_".join((c, image_name))
                for c in (C_PATH_NAME if wants_images else C_OBJECTS_PATH_NAME,
                          C_FILE_NAME if wants_images else C_OBJECTS_FILE_NAME,
                          C_MD5_DIGEST, C_SCALING, C_HEIGHT, C_WIDTH)
            ]
            pathname = m.get_current_image_measurement(m_path)
            filename = m.get_current_image_measurement(m_file)
            rescale = (wants_images and file_setting.rescale.value)

            provider = LoadImagesImageProvider(image_name, pathname, filename,
                                               rescale)
            image = provider.provide_image(image_set)
            pixel_data = image.pixel_data
            if wants_images:
                md5 = provider.get_md5_hash(m)
                m.add_image_measurement("_".join((C_MD5_DIGEST, image_name)),
                                        md5)
                m.add_image_measurement("_".join((C_SCALING, image_name)),
                                        image.scale)
                m.add_image_measurement("_".join((C_HEIGHT, image_name)),
                                        int(pixel_data.shape[0]))
                m.add_image_measurement("_".join((C_WIDTH, image_name)),
                                        int(pixel_data.shape[1]))
                image_set.providers.append(provider)
            else:
                #
                # Turn image into objects
                #
                labels = convert_image_to_objects(pixel_data)
                objects = cpo.Objects()
                objects.segmented = labels
                object_set = workspace.object_set
                assert isinstance(object_set, cpo.ObjectSet)
                object_set.add_objects(objects, image_name)
                add_object_count_measurements(m, image_name, objects.count)
                add_object_location_measurements(m, image_name, labels)
                #
                # Add outlines if appropriate
                #
                if file_setting.wants_outlines:
                    outlines = centrosome.outline.outline(labels)
                    outline_image = cpi.Image(outlines.astype(bool))
                    workspace.image_set.add(file_setting.outlines_name.value,
                                            outline_image)
            statistics += [(image_name, filename)]
        workspace.display_data.col_labels = ("Image name", "File")
        workspace.display_data.statistics = statistics