Class ResizeObservation<TObs, TAct>
Resizes every image observation to (height, width) by OpenCV's area interpolation, as Gymnasium's
ResizeObservation does with cv2.resize(obs, (width, height), interpolation=cv2.INTER_AREA); the
channels, if any, are kept. Use it to shrink frames for a learner.
public class ResizeObservation<TObs, TAct> : TransformObservation<NDArray, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs
Type Parameters
TObsThe env's observation type: uint8 images (NDArray, or object holding them).
TActThe action type, passed through.
- Inheritance
-
ObservationWrapper<NDArray, TObs, TAct>TransformObservation<NDArray, TObs, TAct>ResizeObservation<TObs, TAct>
- Implements
- Inherited Members
- Extension Methods
Remarks
The env's space must be a uint8 Box from 0 to 255 of two or three dimensions. The resize is
Resize(NDArray, (int Width, int Height), int), Gym.NET's translation of OpenCV's kernels, byte for byte equal to the pinned
cv2's (decision DR-23), so no native OpenCV is needed; growing an image takes OpenCV's bilinear emulation
of area interpolation, as cv2 does. Each observation is a new array.
Gymnasium refuses a shape that is not a tuple of integers with TypeError; here it is a
long[], so only its length and signs are checked, with Gymnasium's messages.
Reference: gymnasium/wrappers/transform_observation.py.
Constructors
ResizeObservation(Env<TObs, TAct>, ResizeObservationOptions)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public ResizeObservation(Env<TObs, TAct> env, ResizeObservationOptions options)
Parameters
envEnv<TObs, TAct>The env to wrap.
optionsResizeObservationOptionsThe options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.- TypeError
Thrown when a required argument is unset, with Python's missing-argument message.
ResizeObservation(Env<TObs, TAct>, long[])
Wraps env.
public ResizeObservation(Env<TObs, TAct> env, long[] shape)
Parameters
envEnv<TObs, TAct>The env; its observation space must be a uint8
Boxfrom 0 to 255 of shape(H, W)or(H, W, C).shapelong[]The new
(height, width), both positive.
Exceptions
- TypeError
Thrown when the space is no
Box(Gymnasium's message), orenvis null.- ArgumentNullException
Thrown when
shapeis null.- ValueError
Thrown, with Gymnasium's messages, for a space that is not 2-D or 3-D, not bounded by 0 and 255, or not uint8, and for a shape whose length is not 2 or whose elements are not positive.
Properties
Cv2Shape
The size OpenCV is given, (width, height) (cv2_shape).
public (int Width, int Height) Cv2Shape { get; }
Property Value
Shape
The new (height, width) (shape).
public long[] Shape { get; }
Property Value
- long[]