Class GrayscaleObservation<TObs, TAct>
Converts an RGB image observation to grayscale (0.2125 R + 0.7154 G + 0.0721 B, truncated to uint8), as
Gymnasium's GrayscaleObservation does; keep_dim keeps a channel axis of length 1.
public class GrayscaleObservation<TObs, TAct> : TransformObservation<NDArray, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs
Type Parameters
TObsThe env's observation type: arrays (NDArray, or object holding them).
TActThe action type, passed through.
- Inheritance
-
ObservationWrapper<NDArray, TObs, TAct>TransformObservation<NDArray, TObs, TAct>GrayscaleObservation<TObs, TAct>
- Implements
- Inherited Members
- Extension Methods
Remarks
The weighted sum is NumPy's: the uint8 pixels times float64 weights, summed over the channel axis in float64, then cast to uint8, which truncates. Every observation is a new array.
Reference: gymnasium/wrappers/transform_observation.py.
Constructors
GrayscaleObservation(Env<TObs, TAct>, GrayscaleObservationOptions)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public GrayscaleObservation(Env<TObs, TAct> env, GrayscaleObservationOptions options)
Parameters
envEnv<TObs, TAct>The env to wrap.
optionsGrayscaleObservationOptionsThe options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.
GrayscaleObservation(Env<TObs, TAct>, bool)
Wraps env.
public GrayscaleObservation(Env<TObs, TAct> env, bool keepDim = false)
Parameters
envEnv<TObs, TAct>The env; its observation space must be a uint8
Boxof shape(h, w, 3)with bounds 0 and 255.keepDimboolWhether observations keep a channel axis,
(h, w, 1), instead of(h, w).
Exceptions
- TypeError
Thrown when the space is no
Box(Gymnasium's message), orenvis null.- ValueError
Thrown when the space is not a 3-channel image, or not uint8 within 0 and 255, with Gymnasium's messages.
Properties
KeepDim
Whether the channel axis is kept (keep_dim).
public bool KeepDim { get; }