Sobel edge detector

The Sobel edge detector uses the following two filters

+----+----+----+   +----+----+----+
| -1 |  0 |  1 |   | -1 | -2 | -1 |
+----+----+----+   +----+----+----+
| -2 |  0 |  2 |   |  0 |  0 |  0 |
+----+----+----+   +----+----+----+
| -1 |  0 |  1 |   |  1 |  2 |  1 |
+----+----+----+   +----+----+----+

See also

#!/usr/bin/env ruby
require 'hornetseye'
include Hornetseye
raise "Syntax: sobel.rb <input file> <output file>" if ARGV.size != 2
img = MultiArray.load_ubyte ARGV[0]
edges = Math.hypot( img.sobel( 0 ).to_int,
                    img.sobel( 1 ).to_int ).normalise 0xFF .. 0
edges.save_ubyte ARGV[1]
This is an example on how to compute the Sobel x-gradient.
This is an example on how to compute the Sobel y-gradient.
def sobel(direction)
Compute Sobel-gradient.
Close