# Photofinish Colourgrey Algorithm

##### The Colourgrey Algorithm

The algorithm experts at MIG have developed a photofinish conversion algorithm along with a longtolong implementation for Excel to convert a photo of the finish captured in original colours into historical grey tones.  ##### The colourmathematical background

The RGB colour space consists of the three basic colours red, green and blue with a colour proportion of 0 to 255. In this way more than 16 million colours can be mixed (exactly 256 to the power of 3 = 16,777,216). For example, pure red has the mixing ratio Red (255) – Green (0) – Blue (0). Black results from the mixing ratio of zero shares of Red, Green and Blue (0/0/0). White, on the other hand, has 255 parts of the three primary colours (255/255/255). If the basic colours Red, Green and Blue are mixed in equal parts, the result is a Grey tone somewhere between Black and White. However, from a cubical-mathematical point of view, the question arises as to why there are exactly as many gradations on the cubical greyscale space diagonal with 256 as on the colour cube edges, where the length of the diagonal is √3 (ie, about 1.73 times) of the edges. If the grey scales were arranged at the same distance as the colour grades, then one would expect 443 shades of grey, which can not be reproduced in the RGB colour model. The reason for this can be found in the so-called intermediate-grey theory, according to which virtually infinite grey levels exist between black holes and white light. This eternity grey (e.g.) is simplified in the RGB model by refraction at the diagonal to an integer 256-cube grey. This means that the total of 16,777,216 colours is mapped to only 256 grey tones. For each colour, the closest integer grey on the cube room diagonal is searched, so that each Grey can result from 65536 (16777216 divided by 256) different colours. For example, pure Red (255/0/0) as well as pure Green (0/255/0) and pure Blue (0/0/255) are each converted to the same Grey (85/85/85), as is the Grey himself (Grey h.s., 85/85/85). This is also known as the equalgrey effect (EQ effect).

grey = ((color modulo 256) + (([integer quotient of color divided by 256]) modulo 256) + (([integer quotient of color divided by 256*256]) modulo 256)) divided by 3

##### Longtolong implementation for Microsoft Excel

In Microsoft Excel, each colour is described as a Long data type from 0 (Black) to 16,777,215 (White). For the Colourgrey Algorithm, this means that the grey value is calculated from a colourful long number by RGB splitting (ie the red, green, and blue parts are extracted to values between 0 and 255 and from this the Arithmetic Meangrey (AMG) is calculated by RGB/3 that has a value from 0 to 255) which then represents each of the red, green and blue share and is returned by backward algorithmization as a long-diagonal number.

The complete Colourgrey Algorithm formula is therefore

grey = integer(((color modulo 256) + (([integer quotient of color divided by 256]) modulo 256) + ([integer quotient of color divided by 256*256]) modulo 256)) divided by 3) + ((integer((color modulo 256) + (([integer quotient of color divided by 256]) modulo 256) + (([integer quotient of color divided by 256*256]) modulo 256)) divided by 3) * 256) + ((integer((color modulo 256) + (([integer quotient of color divided by 256]) modulo 256) + (([integer quotient of color divided by 256*256]) modulo 256)) divided by 3) * 256*256)

where color is any Excel Long number from 0 to 16,777,215, the integer quotient is coded with the \ operator and the remainder calculation (modulo) is coded with the Mod operator.

The first application in simulation practice is expected for the GaloppSim version 149.10 (probably at end of November 2018).