rgb2gray — Convert an RGB image to grayscale using luminance weights.
rgb2gray(RGB) converts an MxNx3 truecolor image to an MxN grayscale image with the standard luminance weights.
How rgb2gray works
- Accepts MxNx3 truecolor images.
- Uses weights 0.2989, 0.5870, and 0.1140 for red, green, and blue.
- Preserves uint8, uint16, single, and double image class metadata on host tensors.
Example
Convert RGB To Gray
I = rgb2gray(RGB);Expected output:
% I is MxNRelated Image functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how rgb2gray works, line by line, in Rust.
- View rgb2gray.rs on GitHub
- Learn how the runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.