bounding_box

mpdaf.obj.bounding_box(form, center, radii, shape, posangle=0.0, step=None)[source]

Return Y-axis and X-axis slice objects that bound a rectangular image region that just encloses either an ellipse or a rectangle, where the rectangle has a specified center position, Y-axis and X-axis radii, and a given rotation angle relative to the image axes. The effective center of the region is also returned.

If the ellipse or rectangle is partly outside of the image array, the returned slices are clipped at the edges of the array. The effective center that is returned, is the center before clipping.

Parameters
formstr

The type of region whose rectangle image bounds are needed, chosen from: rectangle, a rotated rectangle or square. ellipse, a rotated ellipse or circle.

centerfloat, float

The floating point array indexes of the centre of the circle, in the order, y,x.

radiifloat or float,float

The half-width and half-height of the ellipse or rectangle. When the posangle is zero, the width and height are parallel to the X and Y axes of the image array, respectively. More generally, the width and height are along directions that are posangle degrees counterclockwise of the X axis and Y axis, respectively. If only one number is specified, then the width and the height are both given that value.

posanglefloat

The counterclockwise rotation angle of the chosen shape, in degrees. When posangle is 0 degrees, the width and height of the shape are along the X and Y axes of the image. Non-zero values of posangle rotate the chosen shape anti-clockwise of that position.

shapeint, int

The dimensions of the image array.

stepfloat, float

The per-pixel world-coordinate increments along the Y and X axes of the image array, or [1.0,1.0] if radii is in pixels.

Returns
outclipped, unclipped, center

The ‘clipped’ return value is a list of the Y-axis and X-axis slices to use to select all pixels within the rectangular region of the image that just encloses the part of the ellipse or rectangle that is within the image area.

The ‘unclipped’ return-value is the version of ‘clipped’ before it was clipped at the edges of the image.

The ‘center’ return value is the pixel index of the center of the region, prior to clipping.

If the region is entirely outside the range of an axis, a zero-pixel slice is returned for that axis in ‘clipped’, with a start value that is 0 if the pixels were all below pixel 0, or shape-1 if they were all off the upper end of the range.