function rgbToGrayscale_(image) {
    const $image = (0, _tensorUtilEnv.convertToTensor)(image, "image", "RGBToGrayscale");
    const lastDimsIdx = $image.rank - 1;
    const lastDims = $image.shape[lastDimsIdx];
    _util.assert($image.rank >= 2, ()=>"Error in RGBToGrayscale: images must be at least rank 2, " + `but got rank ${$image.rank}.`);
    _util.assert(lastDims === 3, ()=>"Error in RGBToGrayscale: last dimension of an RGB image " + `should be size 3, but got size ${lastDims}.`);
    // Remember original dtype so we can convert back if needed
    const origDtype = $image.dtype;
    const fltImage = (0, _cast.cast)($image, "float32");
    const rgbWeights = (0, _tensor1D.tensor1d)([
        0.2989,
        0.5870,
        0.1140
    ]);
    let grayFloat;
    switch($image.rank){
        case 2:
            grayFloat = (0, _einsum.einsum)("ij,j->i", fltImage, rgbWeights);
            break;
        case 3:
            grayFloat = (0, _einsum.einsum)("ijk,k->ij", fltImage, rgbWeights);
            break;
        case 4:
            grayFloat = (0, _einsum.einsum)("ijkl,l->ijk", fltImage, rgbWeights);
            break;
        case 5:
            grayFloat = (0, _einsum.einsum)("ijklm,m->ijkl", fltImage, rgbWeights);
            break;
        case 6:
            grayFloat = (0, _einsum.einsum)("ijklmn,n->ijklm", fltImage, rgbWeights);
            break;
        default:
            throw new Error("Not a valid tensor rank.");
    }
    grayFloat = (0, _expandDims.expandDims)(grayFloat, -1);
    return (0, _cast.cast)(grayFloat, origDtype);
}
Converts images from RGB format to grayscale.

@param image A RGB tensor to convert. The `image`'s last dimension must
    be size 3 with at least a two-dimensional shape.

@doc {heading: 'Operations', subheading: 'Images', namespace: 'image'}