def run(self, workspace): statistics = [] m = workspace.measurements assert isinstance(m, cpmeas.Measurements) 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 digest = hashlib.md5() if wants_images: digest.update(np.ascontiguousarray(pixel_data).data) m.add_image_measurement("_".join((C_MD5_DIGEST, image_name)), digest.hexdigest()) 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 = cellprofiler.cpmath.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
def run(self, workspace): statistics = [] m = workspace.measurements assert isinstance(m, cpmeas.Measurements) 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 digest = hashlib.md5() if wants_images: digest.update(np.ascontiguousarray(pixel_data).data) m.add_image_measurement("_".join((C_MD5_DIGEST, image_name)), digest.hexdigest()) 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 = cellprofiler.cpmath.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
def run(self, workspace): dict = self.get_file_names(workspace) root = self.get_base_directory(workspace) statistics = [("Image name", "File")] m = workspace.measurements for image_name in dict.keys(): file_settings = self.get_file_settings(image_name) rescale = (file_settings.image_objects_choice == IO_IMAGES and file_settings.rescale) provider = LoadImagesImageProvider(image_name, root, dict[image_name], rescale) image = provider.provide_image(workspace.image_set) pixel_data = image.pixel_data if file_settings.image_objects_choice == IO_IMAGES: workspace.image_set.providers.append(provider) # # Add measurements # path_name_category = C_PATH_NAME file_name_category = C_FILE_NAME digest = hashlib.md5() digest.update(np.ascontiguousarray(pixel_data).data) m.add_image_measurement("_".join((C_MD5_DIGEST, image_name)), digest.hexdigest()) 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])) 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 measurements # add_object_count_measurements(m, image_name, objects.count) add_object_location_measurements(m, image_name, labels) path_name_category = C_OBJECTS_PATH_NAME file_name_category = C_OBJECTS_FILE_NAME # # Add outlines if appropriate # if file_settings.wants_outlines: outlines = cellprofiler.cpmath.outline.outline(labels) outline_image = cpi.Image(outlines.astype(bool)) workspace.image_set.add(file_settings.outlines_name.value, outline_image) m.add_image_measurement(file_name_category + '_' + image_name, dict[image_name]) m.add_image_measurement(path_name_category + '_' + image_name, root) statistics += [(image_name, dict[image_name])] if workspace.frame: title = "Load single image: image cycle # %d" % ( workspace.measurements.image_set_number + 1) figure = workspace.create_or_find_figure( title="LoadSingleImage, image cycle #%d" % (workspace.measurements.image_set_number), subplots=(1, 1)) figure.subplot_table(0, 0, statistics)
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
def run(self, workspace): dict = self.get_file_names(workspace) root = self.get_base_directory(workspace) statistics = [("Image name","File")] m = workspace.measurements for image_name in dict.keys(): file_settings = self.get_file_settings(image_name) rescale = (file_settings.image_objects_choice == IO_IMAGES and file_settings.rescale) provider = LoadImagesImageProvider( image_name, root, dict[image_name], rescale) image = provider.provide_image(workspace.image_set) pixel_data = image.pixel_data if file_settings.image_objects_choice == IO_IMAGES: workspace.image_set.providers.append(provider) # # Add measurements # path_name_category = C_PATH_NAME file_name_category = C_FILE_NAME digest = hashlib.md5() digest.update(np.ascontiguousarray(pixel_data).data) m.add_image_measurement("_".join((C_MD5_DIGEST, image_name)), digest.hexdigest()) 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])) 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 measurements # add_object_count_measurements(m, image_name, objects.count) add_object_location_measurements(m, image_name, labels) path_name_category = C_OBJECTS_PATH_NAME file_name_category = C_OBJECTS_FILE_NAME # # Add outlines if appropriate # if file_settings.wants_outlines: outlines = cellprofiler.cpmath.outline.outline(labels) outline_image = cpi.Image(outlines.astype(bool)) workspace.image_set.add(file_settings.outlines_name.value, outline_image) m.add_image_measurement(file_name_category + '_' + image_name, dict[image_name]) m.add_image_measurement(path_name_category + '_' + image_name, root) statistics += [(image_name, dict[image_name])] if workspace.frame: title = "Load single image: image cycle # %d"%(workspace.measurements.image_set_number+1) figure = workspace.create_or_find_figure(title="LoadSingleImage, image cycle #%d"%( workspace.measurements.image_set_number), subplots=(1,1)) figure.subplot_table(0,0, statistics)