def _determine_colorspace(self, colorspace=None, **kwargs):
        """Determine the colorspace from the supplied inputs.

        Parameters
        ----------
        colorspace : str, optional
            Either 'rgb' or 'gray'.
        """
        if colorspace is None:
            # Must infer the colorspace from the image dimensions.
            if len(self.shape) < 3:
                # A single channel image is grayscale.
                self._colorspace = opj2.CLRSPC_GRAY
            elif self.shape[2] == 1 or self.shape[2] == 2:
                # A single channel image or an image with two channels is going
                # to be greyscale.
                self._colorspace = opj2.CLRSPC_GRAY
            else:
                # Anything else must be RGB, right?
                self._colorspace = opj2.CLRSPC_SRGB
        else:
            if colorspace.lower() not in ('rgb', 'grey', 'gray'):
                msg = 'Invalid colorspace "{0}".'.format(colorspace)
                raise IOError(msg)
            elif colorspace.lower() == 'rgb' and self.shape[2] < 3:
                msg = 'RGB colorspace requires at least 3 components.'
                raise IOError(msg)

            # Turn the colorspace from a string to the enumerated value that
            # the library expects.
            COLORSPACE_MAP = {'rgb': opj2.CLRSPC_SRGB,
                              'gray': opj2.CLRSPC_GRAY,
                              'grey': opj2.CLRSPC_GRAY,
                              'ycc': opj2.CLRSPC_YCC}

            self._colorspace = COLORSPACE_MAP[colorspace.lower()]
Determine the colorspace from the supplied inputs.

        Parameters
        ----------
        colorspace : str, optional
            Either 'rgb' or 'gray'.