Generation » Drawing module

Drawing in images

Contents

Functions

void dip::SetBorder(dip::Image& out, Image::Pixel const& value = {0}, dip::UnsignedArray const& sizes = {1})
Sets the pixels at the border of out to value.
void dip::ApplyWindow(dip::Image const& in, dip::Image& out, dip::String const& type = "Hamming", dip::dfloat parameter = 0.5)
Multiplies the image with a windowing function.
void dip::DrawLine(dip::Image& out, dip::UnsignedArray const& start, dip::UnsignedArray const& end, Image::Pixel const& value = {1}, dip::String const& blend = S::ASSIGN)
Draws a Bresenham line in an image.
void dip::DrawLines(dip::Image& out, dip::CoordinateArray const& points, Image::Pixel const& value = {1}, dip::String const& blend = S::ASSIGN)
Draws a series of Bresenham lines in an image.
void dip::DrawPolygon2D(dip::Image& out, dip::Polygon const& polygon, Image::Pixel const& value = {1}, dip::String const& mode = S::FILLED)
Draws a polygon in a 2D image.
void dip::DrawEllipsoid(dip::Image& out, dip::FloatArray const& sizes, dip::FloatArray const& origin, Image::Pixel const& value = {1})
Draws a solid ellipsoid in an image.
void dip::DrawDiamond(dip::Image& out, dip::FloatArray const& sizes, dip::FloatArray const& origin, Image::Pixel const& value = {1})
Draws a solid diamond in an image.
void dip::DrawBox(dip::Image& out, dip::FloatArray const& sizes, dip::FloatArray const& origin, Image::Pixel const& value = {1})
Draws a solid box (rectangle) in an image.
void dip::DrawBandlimitedPoint(dip::Image& out, dip::FloatArray origin, Image::Pixel const& value = {1}, dip::FloatArray sigmas = {1.0}, dip::dfloat truncation = 3.0)
Draws an approximately bandlimited point in the image, in the form of a Gaussian blob.
void dip::DrawBandlimitedLine(dip::Image& out, dip::FloatArray start, dip::FloatArray end, Image::Pixel const& value = {1}, dip::dfloat sigma = 1.0, dip::dfloat truncation = 3.0)
Draws an approximately bandlimited line between two points in the image, using Gaussian profiles.
void dip::DrawBandlimitedBall(dip::Image& out, dip::dfloat diameter, dip::FloatArray origin, Image::Pixel const& value = {1}, dip::String const& mode = S::FILLED, dip::dfloat sigma = 1.0, dip::dfloat truncation = 3.0)
Draws an approximately bandlimited ball (disk) or an n-sphere (circle) in an image, using Gaussian profiles.
void dip::DrawBandlimitedBox(dip::Image& out, dip::FloatArray sizes, dip::FloatArray origin, Image::Pixel const& value = {1}, dip::String const& mode = S::FILLED, dip::dfloat sigma = 1.0, dip::dfloat truncation = 3.0)
Draws an approximately bandlimited box (rectangle) in an image, using Gaussian profiles.

Function documentation

void dip::SetBorder(dip::Image& out, Image::Pixel const& value = {0}, dip::UnsignedArray const& sizes = {1})

Sets the pixels at the border of out to value.

sizes must contain either a single value or one value per image dimension, and indicates how many pixels in from the border are set.

out must not be 0D.

void dip::ApplyWindow(dip::Image const& in, dip::Image& out, dip::String const& type = "Hamming", dip::dfloat parameter = 0.5)

Multiplies the image with a windowing function.

type can be one of the following windowing functions:

  • “Hamming”: A cosine window. Set parameter to 0.5 to get a Hann window, and to 25.0/46.0 to get a Hamming window. With 0.53836, a small refinement to the Hamming optimum, yields the minimum peak side-lobe level.
  • “Gaussian”: A Gaussian window, this is the only one that is isotropic. parameter is the sigma, as a function of the image half-width. Choose a value smaller or equal to 0.5. At 0.5, 4 sigmas fit in the image width.
  • “Tukey”: A rectangular window convolved with a Hann window. parameter is the fraction of image width occupied by the cosine lobe. If parameter is 1.0, it is a Hann window, if it is 0.0 it is a rectangular window.
  • “GaussianTukey”: A rectangular window convolved with a Gaussian window. parameter is the sigma in pixels, a value of the order of 10 is a good choice. The rectangular window is of the size of the image minus 3 sigma on each edge. This is the only window where the tapering is independent of the image width, and thus equal along each image dimension even if the image is not square. If the image size along one dimension is too small to accommodate the window shape, a Gaussian window is created instead.

In all these cases, the window is applied to each dimension independently, meaning that the multi-dimensional window is the outer product of the 1D windows.

void dip::DrawLine(dip::Image& out, dip::UnsignedArray const& start, dip::UnsignedArray const& end, Image::Pixel const& value = {1}, dip::String const& blend = S::ASSIGN)

Draws a Bresenham line in an image.

The line goes from start to end, both points included. These points must be within the image. Pixels in out on the line are set to value, other pixels are not touched. blend can be one of the following strings:

  • "assign": The pixels are set to value.
  • "add": value is added to the pixels using saturated arithmetic.

void dip::DrawLines(dip::Image& out, dip::CoordinateArray const& points, Image::Pixel const& value = {1}, dip::String const& blend = S::ASSIGN)

Draws a series of Bresenham lines in an image.

Lines go from points[0] to points[1], then to points[2], etc, forming a continuous line composed of straight (Bresenham) line segments that hits each of the points in sequence. To create a closed line, repeat the first point at the end.

points must have at least two points, and all points must be within the image. Pixels in out on the lines are set to value, other pixels are not touched. blend can be one of the following strings:

  • "assign": The pixels are set to value.
  • "add": value is added to the pixels using saturated arithmetic.

out must have at least two dimensions.

void dip::DrawPolygon2D(dip::Image& out, dip::Polygon const& polygon, Image::Pixel const& value = {1}, dip::String const& mode = S::FILLED)

Draws a polygon in a 2D image.

Draws a polygon going through each of the points in polygon. mode can be one of the following strings:

  • "open": the start and end points are not connected.
  • "closed": the start and end points are connected.
  • "filled": the polygon is filled, that is, all pixels within the polygon are painted (default).

For a filled polygon, the vertices do not need to be within the image, but for non-filled polygons they must all be within the image.

Pixels in out on the polygon (and within the polygon for filled polygons) are set to value, other pixels are not touched.

The dip::Polygon struct is defined in diplib/chain_code.h, which you’ll need to include to use this function.

out must have two dimensions.

void dip::DrawEllipsoid(dip::Image& out, dip::FloatArray const& sizes, dip::FloatArray const& origin, Image::Pixel const& value = {1})

Draws a solid ellipsoid in an image.

The ellipsoid is centered around the coordinates given by origin, and has a diameter sizes[ii] along dimension ii. That is, the ellipsoid is composed of all pixels within a Euclidean distance of sizes/2 from the origin.

The origin does not need to be within the image. Pixels in out within the ellipsoid are set to value, other pixels are not touched.

out must have at least one dimension.

void dip::DrawDiamond(dip::Image& out, dip::FloatArray const& sizes, dip::FloatArray const& origin, Image::Pixel const& value = {1})

Draws a solid diamond in an image.

The diamond is centered around the coordinates given by origin, and has a width sizes[ii] along dimension ii. That is, the diamond is composed of all pixels within a L-1 distance of sizes/2 from the origin.

The origin does not need to be within the image. Pixels in out within the diamond are set to value, other pixels are not touched.

out must have at least one dimension.

void dip::DrawBox(dip::Image& out, dip::FloatArray const& sizes, dip::FloatArray const& origin, Image::Pixel const& value = {1})

Draws a solid box (rectangle) in an image.

The box is centered around the coordinates given by origin, and has a width sizes[ii] along dimension ii. That is, the box is composed of all pixels within a L-infinity distance of sizes/2 from the origin.

The origin does not need to be within the image. Pixels in out within the box are set to value, other pixels are not touched.

out must have at least one dimension.

void dip::DrawBandlimitedPoint(dip::Image& out, dip::FloatArray origin, Image::Pixel const& value = {1}, dip::FloatArray sigmas = {1.0}, dip::dfloat truncation = 3.0)

Draws an approximately bandlimited point in the image, in the form of a Gaussian blob.

The blob is centered around the coordinates given by origin, and sigmas[ii] is the parameter for the Gaussian along dimension ii. The Gaussian is scaled such that its integral is value. The integral might be off if sigmas contains a small value.

The origin does not need to be within the image. sigmas * truncation is the size of the box around origin that is affected by the blob. Pixels in out within that box have the values of the Gaussian added to them, other pixels are not touched.

out must not be binary, and have at least one dimension.

void dip::DrawBandlimitedLine(dip::Image& out, dip::FloatArray start, dip::FloatArray end, Image::Pixel const& value = {1}, dip::dfloat sigma = 1.0, dip::dfloat truncation = 3.0)

Draws an approximately bandlimited line between two points in the image, using Gaussian profiles.

The two points do not need to be within the image domain.

sigma determines the smoothness of the line. Values are calculated up to a distance of sigma * truncation from the line, further away values are rounded to 0. value is the linear integral perpendicular to the line. That is, it is the weight of the Gaussian used to draw the line. The values are added to existing values in the image out.

out must not be binary and have at least two dimensions.

If start and end are identical, calls dip::DrawBandlimitedPoint.

void dip::DrawBandlimitedBall(dip::Image& out, dip::dfloat diameter, dip::FloatArray origin, Image::Pixel const& value = {1}, dip::String const& mode = S::FILLED, dip::dfloat sigma = 1.0, dip::dfloat truncation = 3.0)

Draws an approximately bandlimited ball (disk) or an n-sphere (circle) in an image, using Gaussian profiles.

The ball is centered around the coordinates given by origin, and has a diameter diameter along all dimensions. The origin does not need to be within the image.

If mode is "empty", a circle/sphere/n-sphere is drawn as a thin shell with a Gaussian profile. If mode is "filled", a disk/ball/hyperball is drawn as a solid shape with an error function transition to background values. The former is the gradient magnitude of the latter.

In both cases, sigma determines the smoothness of the shape, and truncation determines how far out from the edge the smooth values are computed: at a distance of sigma * truncation the values are rounded to 1 or 0. value indicates the weight of the ball: it is the value of the solid shape, and the value of the integral perpendicular to the edge for the empty shape.

The ball is added to the image out. Pixels within sigma * truncation of the ball’s edge have their value increased, other pixels are not touched.

out must not be binary, and have at least one dimension.

Note: diameter is a scalar, unlike for similar functions, because a bandlimited ellipsoid would be very expensive (and complicated) to compute in the spatial domain.

void dip::DrawBandlimitedBox(dip::Image& out, dip::FloatArray sizes, dip::FloatArray origin, Image::Pixel const& value = {1}, dip::String const& mode = S::FILLED, dip::dfloat sigma = 1.0, dip::dfloat truncation = 3.0)

Draws an approximately bandlimited box (rectangle) in an image, using Gaussian profiles.

The box is centered around the coordinates given by origin, and has a width of sizes[ii] along dimension ii. The origin does not need to be within the image.

If mode is "empty", the edge of the rectangle or the surface of the box is drawn as a thin shell with a Gaussian profile. If mode is "filled", the rectangle/box is drawn as a solid shape with an error function transition to background values. The former is the gradient magnitude of the latter.

In both cases, sigma determines the smoothness of the shape, and truncation determines how far out from the edge the smooth values are computed: at a distance of sigma * truncation the values are rounded to 1 or 0. value indicates the weight of the ball: it is the value of the solid shape, and the value of the integral perpendicular to the edge for the empty shape.

The box is added to the image out. Pixels within sigma * truncation of the box’s edge have their value increased, other pixels are not touched.

out must not be binary, and have at least one dimension.