Development Pages
Dave
COLLIER

 

 
 
Edge Detection Scripts
I am taking a somewhat different approach
T
here are some standard, or widely-used, mechanisms for edge detection, based on the formulas devised by John F. Canny in 1986, as may be seen on Wikipedia. Rigorous and showing impressive results, but for me there is a problem, for I am looking at edge detection in the identification of shapes, the Canny formulas do not, so far as I tell, attempt to do that, they are concerned with drawing a line around everything. To look more towards shape identification, I have been working on devising my own edge-detection scripts, which show results that are not too bad in terms of drawing lines round shapes, and are a work in progress with the aim of allowing more flexibility.
An implementation of the Canny formula is available on http://canny-edge-detection.herokuapp.com/. Running a photo through that software with the Sobel Operator gives results as shown here. Usually the result of Canny formula processing is white lines on black, which may be because inverting to black on white highlights where a major problem lies, which can be that there are so many lines that you may as well have stuck with the photograph in the first place.
Each of these images may be clicked on to expand to full-screen or 2048 pixels, whichever is the smaller.
original pic
Colour photo
Canny Sobel
Photo processed with Canny formula and Sobel filter.
Canny Sobel Inverse
Photo processed with Canny formula and Sobel filter, inversed to black on white.
Canny Sobel non-maximal suppression
Photo processed with Canny formula and Sobel filter, non-maximum suppression.
Canny Sobel non-maximal suppression inversed
Photo processed with Canny formula and Sobel filter, non-maximum suppression, inversed to black on white.
Edge Detect by Brightness Level
Photo processed with my Edge Detect by Brightness Level script, 7 equal brightnesses auto-colour and auto-transparency generation.
I must reinforce that my edge-detection software is a work in progress, however it should be apparent from the above images that while the Canny formulas produce very impressive results, they are not the right tool for identifying shapes. Mine is not perfect (yet!), but on the road there I hope.
Currently I have two mechanisms for identifing edges: Edge Detect by Brightness Level and Edge Detect by Hue and Brightness.
Edge Detect By Brightness Level
The user selects any number of points on the table of 256 brightness levels, or this can be done automatically where the software will identify equal number of brightnesses among the pixels in the image. Each selection therefore forms a band, from the lower brightness level selected to itself. For each pixel, the band that its brightness falls in is established, as is the band of the pixel to the right of it and that immediately below it on the image, the higher of the differences between these two, i.e. the one to the right and the one below, and the brightness of the pixel being looked at, provides a value between 0 and 255, this value is used to determine the opacity of the output pixel, the higher the value the more opaque, with its colour being that which is given as the top of the band by the user.
That sounds a little complex, though is in fact more difficult to explain that it is to code, the code is quite concise. And it seems to work very well, and be quite flexible in getting towards the determination of shapes. It is somewhat different from the approach taken by Canny and those who have extended his work, but works better for what I am trying to achieve.
The Canny formula first has the image converted to greyscale – well you don’t need to do that, all we’re looking for is the brightness level of each pixel, which is what the conversion to greyscale is intended to achieve. Rather than go to that trouble, my code simply runs through the pixels and holds the brightness level of each pixel in memory – this could be seen as problematic with a large image and so it would be, but my scripts split the picture up into sections, so there should be no timeouts or memory problems.
The other concern about converting to greyscale is what formula you choose to do that. Canny gives I believe no guidance on this and it looks like people who’ve devised code for it don’t say which they use. This can make a difference to the result, see my page Formulas for Calculating Pixel Brightness (i.e. Greyscale), though it’s possible not too much difference in the creation of outlines, they won’t be the same outlines with each greyscale formula, but may look OK with all of them for the purposes of outlines.
The second stage of Canny processing is to perform a Gaussian blur on the image. I purposely do not do this with my scripts, as I think it is better done separately, with Photoshop or whatever, for tighter control.
Currently my scripts do not take into account anti-aliasing or Gaussian blur, they work only on immediately adjoining pixels. I am working on enhancing the scripts in this regard.
Edge Detect By Hue and Brightness
The user selects a gap between brightnesses, and a gap between hues in the 360° colour circle, then the script works in principle similarly to Edge Detect By Brightness Level as above. The results are also surprisingly effective, though tend towards the problem intrinsic in Canny, that while the outlines look reasonably convincing, they are less useful for shape identification. I am working on this as I think that identification by hue should be significant, the existing script doesn’t quite do what I am looking for.
Edge Detect by Hue and Brightness
Photo processed with my Hue and Brightness Edge Detection script, brightness diff 40, hue diff 40°, grey/black at V less than 11%. As can be seen, needs more work to differentiate for shape identification.

 

 
admin login
Dave Collier 2020 . . . email me . . .