The widely – and not so widely – used formulas for edge detection mostly or all argue for converting an image to greyscale before analysis. Follow links to Edge Detection formulas on the Wikipedia page for
Edge Detection.
All very well, but they never seem to say what formula they use for converting an image to greyscale.
That can be quite significant as the examples on this page should show. A perceptual edge between two areas of the same brightness calculation (i.e. they would equate to exactly the same shade of grey) can be quite pronounced. You see it as an edge, but if the greyscale conversion doesn’t identify that as as edge because it converts both colours to the same grey, can the edge detection software ever work satisfactorily?
As with many issues relating to relative brightness analysis, this may not matter much in the general sceme of things as the results will be good enough. Though good enough for what? I wonder whether some of the ever more complex mathematics that is being applied to this is the result of the classic academic slipup, charging down the research tunnel when one of the basic concepts is flawed.
T
his page attempts to demonstrate edges. Each block of coloured text has a background and foreground (i.e. text) of equal brightness (i.e. equal greyscale) by brightness calculation. IF CONVERTED TO GREYSCALE, THEREFORE, THERE WILL BE NO EDGES. If you can clearly see edges in the coloured block (as you almost certainly can) then that formula for converting to greyscale is not going to be adequate for edge detection to take place accurately.
For an explanation of the formulas used in these samples see my page
Formulas for Calculating Pixel Brightness (i.e. Greyscale)).
N
o formula calculates relative brightness absolutely accurately, see my page
Equivalent Colour Brightnesses. For this reason my edge detection routines take hue into consideration as well as greyscale.
See the foot of the page for comments regarding colour blindness.
Demo 1. This uses the oft-recommened Lightness calculation for greyscale, a simple linear formula made by adding the highest of the red, green and blue brightness levels to the lowest, and dividing the result by 2.
Lightness formula at brightness 138
RGB 20,255,20 (green) and 255,20,20 (red) both give a brightness of 138 using the Lightness formula.
Demo 2. This uses the also oft-recommened Average calculation for greyscale, a simple linear formula made by adding the red, green and blue brightness levels together and dividing the result by 3.
Average formula at brightness 138
RGB 79,255,79 (green) and 255,79,79 (red) both give a brightness of 138 using the Average formula.
Demo 3. This uses the YIQ weighted formula factors R: 0.299, G: 0.587, B: 0.114. The YIQ factors applied linearly are those recommended by the WWW consortium (W3C) for determining colour contrast of text on web pages, see
W3C Working Draft Checkpoint 2.1.
YIQ weighted formula at brightness 138
RGB 0,235,0 (green) and 255,88,88 (red) both give a brightness of 138 using the YIQ weighted formula.
Demo 4. This uses the sRGB gamma-decompress, weighted sum then gamma-recompress method. formula factors R: 0.2235, G: 0.7154, B: 0.0611 and a gamma exponent of 2.4.
sRGB gamma weighted formula at brightness 138
RGB 0,161,0 (green) and 255,56,56 (red) both give a brightness of 138 using the sRGB gamma-decompress, weighted sum then gamma-recompress method..