本文整理汇总了Python中pgmagick.Image.erase方法的典型用法代码示例。如果您正苦于以下问题:Python Image.erase方法的具体用法?Python Image.erase怎么用?Python Image.erase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmagick.Image
的用法示例。
在下文中一共展示了Image.erase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_substack_no_rotation
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import erase [as 别名]
#.........这里部分代码省略.........
# The images are generated per slice, so most of the following
# calculations refer to 2d images.
# Each stack to export is treated as a separate channel. The order
# of the exported dimensions is XYCZ. This means all the channels of
# one slice are exported, then the next slice follows, etc.
cropped_stack = []
# Accumulator for estimated result size
estimated_total_size = 0
# Iterate over all slices
for nz in range(n_slices):
for stack in job.stacks:
bb = s_to_bb[stack.id]
# Shortcut for tile width and height
tile_width = stack.tile_width
tile_height = stack.tile_height
# Get indices for bounding tiles (0 indexed)
tile_x_min = int(bb.px_x_min / tile_width)
tile_x_max = int(bb.px_x_max / tile_width)
tile_y_min = int(bb.px_y_min / tile_height)
tile_y_max = int(bb.px_y_max / tile_height)
# Get the number of needed tiles for each direction
num_x_tiles = tile_x_max - tile_x_min + 1
num_y_tiles = tile_y_max - tile_y_min + 1
# Associate image parts with all tiles
image_parts = []
x_dst = bb.px_x_offset
for nx, x in enumerate( range(tile_x_min, tile_x_max + 1) ):
# The min x,y for the image part in the current tile are 0
# for all tiles except the first one.
cur_px_x_min = 0 if nx > 0 else bb.px_x_min - x * tile_width
# The max x,y for the image part of current tile are the tile
# size minus one except for the last one.
if nx < (num_x_tiles - 1):
cur_px_x_max = tile_width - 1
else:
cur_px_x_max = bb.px_x_max - x * tile_width
# Reset y destination component
y_dst = bb.px_y_offset
for ny, y in enumerate( range(tile_y_min, tile_y_max + 1) ):
cur_px_y_min = 0 if ny > 0 else bb.px_y_min - y * tile_height
if ny < (num_y_tiles - 1):
cur_px_y_max = tile_height - 1
else:
cur_px_y_max = bb.px_y_max - y * tile_height
# Create an image part definition
z = bb.px_z_min + nz
path = job.get_tile_path(stack, (x, y, z))
try:
part = ImagePart(path, cur_px_x_min, cur_px_x_max,
cur_px_y_min, cur_px_y_max, x_dst, y_dst)
image_parts.append( part )
except:
# ignore failed slices
pass
# Update y component of destination position
y_dst += cur_px_y_max - cur_px_y_min
# Update x component of destination position
x_dst += cur_px_x_max - cur_px_x_min
# Write out the image parts and make sure the maximum allowed file
# size isn't exceeded.
cropped_slice = None
for ip in image_parts:
# Get (correctly cropped) image
image = ip.get_image()
# Estimate total file size and abort if this exceeds the
# maximum allowed file size.
estimated_total_size = estimated_total_size + ip.estimated_size
if estimated_total_size > settings.GENERATED_FILES_MAXIMUM_SIZE:
raise ValueError("The estimated size of the requested image "
"region is larger than the maximum allowed "
"file size: %0.2f > %s Bytes" % \
(estimated_total_size,
settings.GENERATED_FILES_MAXIMUM_SIZE))
# It is unfortunately not possible to create proper composite
# images based on a canvas image newly created like this:
# cropped_slice = Image( Geometry(bb.width, bb.height), Color("black"))
# Therefore, this workaround is used.
if not cropped_slice:
cropped_slice = Image(image)
cropped_slice.backgroundColor("black")
cropped_slice.erase()
# The '!' makes sure the aspect ration is ignored
cropped_slice.scale('%sx%s!' % (bb.width, bb.height))
# Draw the image onto result image
cropped_slice.composite( image, ip.x_dst, ip.y_dst, co.OverCompositeOp )
# Delete tile image - it's not needed anymore
del image
if cropped_slice:
# Optionally, use only a single channel
if job.single_channel:
cropped_slice.channel( ChannelType.RedChannel )
# Add the image to the cropped stack
cropped_stack.append( cropped_slice )
return cropped_stack