When I make a composite raster in QGIS using the GRASS r.composite tool and then click on a certain cell I get these values in the blue/green/red/composite rasters: blue = 124 green = 124 red = 172 composite = 15861.

I know that the blue/green/red represent the brightness values of the given bands. What does the 15861 represent and how is it calculated?

  • 1
    It's likely an integer value representing the alpha composite: docstore.mik.ua/orelly/java-ent/jfc/ch04_07.htm – WhiteboxDev Oct 22 '14 at 22:49
  • 1
    What version of QGIS and Grass are you using? Also, please state your settings as they impact the operation (and therefore calculation of r.composite). Interestingly, I consistently only get RGB and no composite band in 2.4. – MappaGnosis Oct 24 '14 at 7:20
  • I am using QGIS 2.2 on Windows 7 with the GRASS 6.4.3 GUI. For settings, I am using 32 for number of values for red, green, and blue. The tutorial that I am using is the FOSS4G Academy course on Remote Sensing. The tutorial document is at foss4geo.files.wordpress.com/2014/08/module-3-lab2.pdf. – Jim O'Leary Oct 24 '14 at 15:20
  • 2
    Please, read the manual for r.composite. If you use the "default" intensity levels for each component (that is 32), you should get slightly different RGB values compared to the "input" RGB. You may want to use r.what with the -r parameter (Output color values as RRR:GGG:BBB) to query a cell's RGB combination. Also to look at r.what.color. [Links to GRASS6, as this is the version the OP uses]. – Nikos Alexandris Feb 28 '15 at 10:03
  • 1
    Check also this thread: lists.osgeo.org/pipermail/grass-user/2015-January/071739.html. – Nikos Alexandris Feb 28 '15 at 10:07

The number 124 as a binary byte (eight digits) is 01111100. To represent an RGB triple of three bytes would require three times eight, or 24, such bits. By default, r.composite reduces this to just 15 bits by discarding the least significant bits in each band. Thus, it trims 01111100 to 01111, which is 15. (Equivalently, it divides 124 by 8 and ignores the remainder.) Apparently these three five-bit results are concatenated in the order B, G, R to form a 15-bit number (representing values between 0 and 2^15-1 = 32767, which is small enough to keep the color table to a manageable size). These values therefore represent three image bands, each with just five bits of precision rather than the original eight.

In the example of the question, the calculations proceed like this:

  1. Blue = 124 is converted to 124/8 = 15 (plus a neglected remainder of 4). In binary this is 01111.

  2. Green = 124 is converted to 124/8 = 15 (plus a neglected remainder of 4). In binary this is 01111.

  3. Red = 172 is converted to 172/8 = 21 (plus a neglected remainder of 4). In binary this is 10101.

  4. The digits are concatenated into 01111 01111 10101. This 15-digit binary number represents the value 15861 = (15*32 + 15)*32 + 21.

r.composite may do more processing than this, and it may do it slightly differently depending on the options you supply, but these operations do show the basic way in which a byte can be converted to a five-bit value.

You can approximately reverse the procedure using successive divisions by 32:

  1. 15861/32 = 495 plus a remainder of 21. (Multiplied by 8, this remainder of 21 gives 168, which is only a little bit less than the original 172 for the red band.)

  2. 495/32 = 15 plus a remainder of 15. (Multiplied by 8, this remainder of 15 gives 120, which is only a little bit less than the original 124 for the green band.)

  3. We are left with 15, which when multiplied by 8 gives 120, which is only a little bit less than the original 124 for the blue band.


r.composite manual page at https://grass.osgeo.org/grass72/manuals/r.composite.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.