Function Repository Resource:

OneChannelGrayscale

Source Notebook

Convert a three-channel color RGB image to a one-channel grayscale image or matrix

Contributed by: Daniel de Souza Carvalho

ResourceFunction["OneChannelGrayscale"][img]

converts color image img to a single-channel grayscale image.

ResourceFunction["OneChannelGrayscale"][img,"ImageData"]

returns the image data matrix of the grayscale image.

Details

OneChannelGrayscale converts a color three-channel RGB image to gray-scale by one of two different algorithms. Output is a one-channel image or matrix of grayscale values.
ResourceFunction["OneChannelGrayscale"] supports a Method option with the following values:
"Luminosity" (default)uses the luminosity algorithm, which is a weighted average
"Mean"uses the mean algorithm on the 3 channel RGB colors pixels

Examples

Basic Examples (3) 

Convert a color image to a grayscale:

In[1]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/1e116a42-d09b-4d09-b5b6-225e2ea5a7f3"]
Out[1]=

Look at the image information:

In[2]:=
Information[%]
Out[2]=

Convert the same image to grayscale using the mean algorithm:

In[3]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/67db657b-b7ca-468f-afe5-4ca2e056f9b5"]
Out[3]=

Options (2) 

2D numerical matrix can be seen with ArrayPlot:

In[4]:=
# -> ArrayPlot[
    ResourceFunction["OneChannelGrayscale"][#, "Matrix", Method -> "Mean"], Frame -> None, ColorFunction -> GrayLevel] &[
 ResourceFunction["GetLoremFlickrImage"]["dometic cat"]]
Out[4]=

Convert an AI image synthesis to grayscale:

In[5]:=
GraphicsGrid[{{#, ArrayPlot[
      ResourceFunction["OneChannelGrayscale"][#, "Matrix", Method -> "Mean"], Frame -> None, ColorFunction -> GrayLevel]}}] &[
 ImageSynthesize[
  "White cat with red hat, blue glasses in a green forest background photo realistic"]]
Out[5]=

Applications (3) 

Image exams, such as X-rays or mammograms, are in gray scale. Still, the images are usually 3-channel RGB, it is better to convert to one channel grayscale for faster computation and clean up data:

In[6]:=
ResourceFunction["OneChannelGrayscale"] /@ WebImageSearch["x-ray femur", 3]
Out[6]=

Find a general test image and convert to grayscale:

In[7]:=
dog = Entity["TaxonomicSpecies", "CanisLupusFamiliaris::4t62p"][
   EntityProperty["TaxonomicSpecies", "Image"]];
golden = ResourceFunction["OneChannelGrayscale"][dog];
GraphicsRow[{dog, golden}]
Out[8]=

Compare information for the images:

In[9]:=
Row[Information /@ {dog, golden}]
Out[9]=

Convert an image to grayscale and then colorize it using ArrayPlot:

In[10]:=
ArrayPlot[
 ResourceFunction["OneChannelGrayscale"][
  GeoGraphics[{Entity["HistoricalSite", "ChristTheRedeemer::g488w"]}],
   "Matrix", Method -> "Mean"], Frame -> None, ColorFunction -> "Rainbow"]
Out[10]=

Properties and Relations (3) 

Convert three faces to grayscale:

In[11]:=
faces = ResourceFunction["CreateFace"][3];
In[12]:=
ResourceFunction["OneChannelGrayscale"] /@ faces
Out[12]=

Convert the same faces using the unweighted mean:

In[13]:=
ResourceFunction["OneChannelGrayscale"][#, Method -> "Mean"] & /@ faces
Out[13]=

Compare to the resource function "FaustGrayscaleConvert":

In[14]:=
ResourceFunction["FaustGrayscaleConvert"] /@ faces
Out[14]=

Publisher

Daniel de Souza Carvalho

Version History

  • 1.0.0 – 24 November 2025

Source Metadata

Related Resources

Author Notes

It computes just the 3 RGB channels, ignoring other channels if they exist in the source image. Those algorithms are not reversible, we can get back to the RGB colorful source image. It is useful for early image computation. It is useful for machine learning. It is useful to reduce the image byte size for disk storage and memory computation. Application in medical exam image analysis. Applications in artificial intelligence machine learning.

License Information