示例#1
0
    def export_single_node(self, connector_link):
        """ Exports a single connector and expects the output path to be existing
        and writable.
        """
        connector = connector_link.connector

        # Calculate bounding box for current connector
        x_min = connector.location.x - self.job.x_radius
        x_max = connector.location.x + self.job.x_radius
        y_min = connector.location.y - self.job.y_radius
        y_max = connector.location.y + self.job.y_radius
        z_min = connector.location.z - self.job.z_radius
        z_max = connector.location.z + self.job.z_radius
        rotation_cw = 0
        zoom_level = 0

        # Create a single file for each section (instead of a mulipage TIFF)
        crop_self = CropJob(self.job.user, self.job.project_id,
                self.job.stack_id, x_min, x_max, y_min, y_max, z_min, z_max,
                rotation_cw, zoom_level, single_channel=True)
        cropped_stack = extract_substack(crop_self)
        # Save each file in output path
        connector_path = self.create_path(connector_link)
        for i, img in enumerate(cropped_stack):
            # Save image in output path, named after the image center's coordinates,
            # rounded to full integers.
            x = int(connector.location.x + 0.5)
            y = int(connector.location.y + 0.5)
            z = int(z_min + i * crop_self.stacks[0].resolution.z  + 0.5)
            image_name = "%s_%s_%s.tiff" % (x, y, z)
            connector_image_path = os.path.join(connector_path, image_name)
            img.write(connector_image_path)
示例#2
0
文件: roi.py 项目: tomka/CATMAID
def create_roi_image_task(user, project_id, roi_id, file_path):
    lock_id = create_lock_name(roi_id)
    # memcache delete is very slow, but we have to use it to take
    # advantage of using add() for atomic locking
    release_lock = lambda: cache.delete(lock_id)
    logger.debug("Creating cropped image for ROI with ID %s" % roi_id)
    try:
        # Get ROI
        roi = RegionOfInterest.objects.get(id=roi_id)
        # Prepare parameters
        hwidth = roi.width * 0.5
        x_min = roi.location_x - hwidth
        x_max = roi.location_x + hwidth
        hheight = roi.height * 0.5
        y_min = roi.location_y - hheight
        y_max = roi.location_y + hheight
        z_min = z_max = roi.location_z
        single_channel = False
        # Create a cropping job
        job = cropping.CropJob(user, project_id, [roi.stack.id],
            x_min, x_max, y_min, y_max, z_min, z_max, roi.rotation_cw,
            roi.zoom_level, single_channel)
        # Create the pgmagick images
        cropped_stacks = cropping.extract_substack( job )
        if len(cropped_stacks) == 0:
            raise StandardError("Couldn't create ROI image")
        # There is only one image here
        img = cropped_stacks[0]
        img.write(str(file_path))
    finally:
        release_lock()

    return "Created image of ROI %s" % roi_id
示例#3
0
    def export_single_node(self, treenode):
        """ Exports a treenode and expects the output path to be existing
        and writable.
        """
        # Calculate bounding box for current connector
        x_min = treenode.location.x - self.job.x_radius
        x_max = treenode.location.x + self.job.x_radius
        y_min = treenode.location.y - self.job.y_radius
        y_max = treenode.location.y + self.job.y_radius
        z_min = treenode.location.z - self.job.z_radius
        z_max = treenode.location.z + self.job.z_radius
        rotation_cw = 0
        zoom_level = 0

        # Create a single file for each section (instead of a mulipage TIFF)
        crop_self = CropJob(self.job.user, self.job.project_id,
                self.job.stack_id, x_min, x_max, y_min, y_max, z_min, z_max,
                rotation_cw, zoom_level, single_channel=True)
        cropped_stack = extract_substack(crop_self)
        # Save each file in output path
        output_path = self.create_path(treenode)
        for i, img in enumerate(cropped_stack):
            # Save image in output path, named <treenode-id>.tiff
            image_name = "%s.tiff" % treenode.id
            treenode_image_path = os.path.join(output_path, image_name)
            img.write(treenode_image_path)