Provides a wrapper around skimage.draw to allow easy drawing of objects onto images.
This class allows access the user to draw simply shapes on an image (or its mask) by specifying the desired shape
and geometry (centre, length/width etc). Mostly this implemented by pass throughs to the skimage.draw
module, but methods are provided for an annulus, rectangle (and square) and rectangle-perimeter meothdds- the
latter offering rotation about the centre point in contrast to the skimage.draw equivalents.
No state data is stored with this class so the attribute does not need to be serialised when the parent ImageFile
is saved.
Middle control point weight, it describes the line tension.
shapetuple, optional
Image shape which is used to determine the maximum extent of output
pixel coordinates. This is useful for curves that exceed the image
size. If None, the full extent of the curve is used.
r,c (int) – coordinates of the centre of the circle to be drawn.
radius (float) – Radius of the circle
Keyword Arguments:
shape (tuple) – Image shape as a tuple of size 2. Determines the maximum extent of output
pixel coordinates. This is useful for disks that exceed the image size. If None, the full
extent of the disk is used. The shape might result in negative coordinates and wraparound
behaviour.
bresenham : Bresenham method (default)
andres : Andres method
shapetuple, optional
Image shape which is used to determine the maximum extent of output
pixel coordinates. This is useful for circles that exceed the image
size. If None, the full extent of the circle is used. Must be at least
length 2. Only the first two values are used to determine the extent of
the input image.
Andres method presents the advantage that concentric
circles create a disc whereas Bresenham can make holes. There
is also less distortions when Andres circles are rotated.
Bresenham method is also known as midpoint circle algorithm.
Anti-aliased circle generator is available with circle_perimeter_aa.
Image shape which is used to determine the maximum extent of output
pixel coordinates. This is useful for circles that exceed the image
size. If None, the full extent of the circle is used. Must be at least
length 2. Only the first two values are used to determine the extent of
the input image.
Image shape as a tuple of size 2. Determines the maximum
extent of output pixel coordinates. This is useful for disks that
exceed the image size. If None, the full extent of the disk is used.
The shape might result in negative coordinates and wraparound
behaviour.
Minor and major semi-axes. (r/r_radius)**2+(c/c_radius)**2=1.
shapetuple, optional
Image shape which is used to determine the maximum extent of output pixel
coordinates. This is useful for ellipses which exceed the image size.
By default the full extent of the ellipse are used. Must be at least
length 2. Only the first two values are used to determine the extent.
rotationfloat, optional (default 0.)
Set the ellipse rotation (rotation) in range (-PI, PI)
in contra clock wise direction, so PI/2 degree means swap ellipse axis
Note that the positions of ellipse without specified shape can have
also, negative values, as this is correct on the plane. On the other hand
using these ellipse positions for an image afterwards may lead to appearing
on the other side of image, because image[-1,-1]=image[end-1,end-1]
Minor and major semi-axes. (r/r_radius)**2+(c/c_radius)**2=1.
orientationdouble, optional
Major axis orientation in clockwise direction as radians.
shapetuple, optional
Image shape which is used to determine the maximum extent of output
pixel coordinates. This is useful for ellipses that exceed the image
size. If None, the full extent of the ellipse is used. Must be at
least length 2. Only the first two values are used to determine the
extent of the input image.
Note that the positions of ellipse without specified shape can have
also, negative values, as this is correct on the plane. On the other hand
using these ellipse positions for an image afterwards may lead to appearing
on the other side of image, because image[-1,-1]=image[end-1,end-1]
If True, returns the level set for this ellipsoid (signed level
set about zero, with positive denoting interior) as np.float64.
False returns a binarized version of said level set.
Ellipsoid centered in a correctly sized array for given spacing.
Boolean dtype unless levelset=True, in which case a float array is
returned with the level set above 0.0 representing the ellipsoid.
Whether to include the endpoint in the returned line. Defaults
to False, which allows for easy drawing of multi-point paths.
integerbool, optional
Whether to round the coordinates to integer. If True (default),
the returned coordinates can be used to directly index into an
array. False could be used for e.g. vector drawing.
Image shape which is used to determine the maximum extent of output
pixel coordinates. This is useful for polygons that exceed the image
size. If None, the full extent of the polygon is used. Must be at
least length 2. Only the first two values are used to determine the
extent of the input image.
If the image shape is defined and vertices / points of the polygon are
outside this coordinate space, only a part (or none at all) of the polygon’s
pixels is returned. Shifting the polygon’s vertices by an offset can be used
to move the polygon around and potentially draw an arbitrary sub-region of
the polygon.
If vertices / points of the polygon are outside the coordinate space
defined by image_shape, only a part (or none at all) of the polygon is
drawn in the mask.
Image shape which is used to determine maximum extents of output pixel
coordinates. This is useful for polygons that exceed the image size.
If None, the full extents of the polygon is used. Must be at least
length 2. Only the first two values are used to determine the extent of
the input image.
clipbool, optional
Whether to clip the polygon to the provided shape. If this is set
to True, the drawn figure will always be a closed polygon with all
edges visible.
Generate an image with random shapes, labeled with bounding boxes.
The image is populated with random shapes with random sizes, random
locations, and random colors, with or without overlap.
Shapes have random (row, col) starting coordinates and random sizes bounded
by min_size and max_size. It can occur that a randomly generated shape
will not fit the image at all. In that case, the algorithm will try again
with new starting coordinates a certain number of times. However, it also
means that some shapes may be skipped altogether. In that case, this
function will generate fewer shapes than requested.
The number of rows and columns of the image to generate.
max_shapesint
The maximum number of shapes to (attempt to) fit into the shape.
min_shapesint, optional
The minimum number of shapes to (attempt to) fit into the shape.
min_sizeint, optional
The minimum dimension of each shape to fit into the image.
max_sizeint, optional
The maximum dimension of each shape to fit into the image.
num_channelsint, optional
Number of channels in the generated image. If 1, generate monochrome
images, else color images with multiple channels. Ignored if
multichannel is set to False.
The name of the shape to generate or None to pick random ones.
intensity_range{tuple of tuples of uint8, tuple of uint8}, optional
The range of values to sample pixel values from. For grayscale
images the format is (min, max). For multichannel - ((min, max),)
if the ranges are equal across the channels, and
((min_0, max_0), … (min_N, max_N)) if they differ. As the
function supports generation of uint8 arrays only, the maximum
range is (0, 255). If None, set to (0, 254) for each channel
reserving color of intensity = 255 for background.
allow_overlapbool, optional
If True, allow shapes to overlap.
num_trialsint, optional
How often to attempt to fit a shape into the image before skipping it.
rng{numpy.random.Generator, int}, optional
Pseudo-random number generator.
By default, a PCG64 generator is used (see numpy.random.default_rng()).
If rng is an int, it is used to seed the generator.
channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image.
Otherwise, this parameter indicates which axis of the array corresponds
to channels.
Added in version 0.19: channel_axis was added in 0.19.
A list of labels, one per shape in the image. Each label is a
(category, ((r0, r1), (c0, c1))) tuple specifying the category and
bounding box coordinates of the shape.