Skip to content

Instantly share code, notes, and snippets.

@dannvix
Created March 22, 2012 08:27
Show Gist options
  • Save dannvix/2157143 to your computer and use it in GitHub Desktop.
Save dannvix/2157143 to your computer and use it in GitHub Desktop.
Kirsch filter with RMagick
class Kirsch
require 'RMagick'
include Magick
@@kernel = [
5, 5, -3, 5, 0, -3, -3, -3, -3,
5, 5, 5, -3, 0, -3, -3, -3, -3,
-3, 5, 5, -3, 0, 5, -3, -3, -3,
-3, -3, 5, -3, 0, 5, -3, -3, 5,
0, 0, 0, 0, 0, 0, 0, 0, 0,
5, -3, -3, 5, 0, -3, 5, -3, -3,
-3, -3, -3, 5, 0, -3, 5, 5, -3,
-3, -3, -3, -3, 0, -3, 5, 5, 5,
-3, -3, -3, -3, 0, 5, -3, 5, 5
]
def self.apply (source)
source.dup.quantize(256, GRAYColorspace).convolve(9, @@kernel)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment