class_docstr: Grayscale wrapper for gym.Env, converting frames to grayscale.
  
  Only works with gym.spaces.Box environment with 2D RGB frames.
  The last dimension (RGB) of environment observation space will be removed.
  
  Example:
      env = gym.make('Env')
      # env.observation_space = (100, 100, 3)
  
      env_wrapped = Grayscale(gym.make('Env'))
      # env.observation_space = (100, 100)
  
  Args:
      env (gym.Env): Environment to wrap.
  
  Raises:
      ValueError: If observation space shape is not 3
          or environment is not gym.spaces.Box.
class_docstr_tok: ["Grayscale","wrapper","for","gym.Env",",","converting","frames","to","grayscale",".","Only","works","with","gym.spaces.Box","environment","with","2D","RGB","frames",".","The","last","dimension","(","RGB",")","of","environment","observation","space","will","be","removed",".","Example",":","env","=","gym.make","(","'Env","'",")","#","env.observation_space","=","(","100",",","100",",","3",")","env_wrapped","=","Grayscale","(","gym.make","(","'Env","'",")",")","#","env.observation_space","=","(","100",",","100",")","Args",":","env","(","gym.Env",")",":","Environment","to","wrap",".","Raises",":","ValueError",":","If","observation","space","shape","is","not","3","or","environment","is","not","gym.spaces.Box","."]
code: def __init__(self, env):
      if not isinstance(env.observation_space, gym.spaces.Box):
          raise ValueError(
              "Grayscale only works with gym.spaces.Box environment."
          )
  
      if len(env.observation_space.shape) != 3:
          raise ValueError("Grayscale only works with 2D RGB images")
  
      super().__init__(env)
  
      _low = env.observation_space.low.flatten()[0]
      _high = env.observation_space.high.flatten()[0]
      assert _low == 0
      assert _high == 255
      self._observation_space = gym.spaces.Box(
          _low,
          _high,
          shape=env.observation_space.shape[:-1],
          dtype=np.uint8,
      )
  
file_path: garage/src/garage/envs/wrappers/grayscale.py
imports: import warnings
  import gym
  import gym.spaces
  import numpy
  from skimage import color, img_as_ubyte
label_desc: Use image node_id 1 to create a new Grayscale object from inherited base classes: gym with example: obj = Grayscale(env)