I want to do a thing like this:
http://reference.wolfram.com/language/ref/MaxFilter.html
Lets say my image has one channel (is grayscale).
I want to do a thing like this:
http://reference.wolfram.com/language/ref/MaxFilter.html
Lets say my image has one channel (is grayscale).
Here is how I did it with PI * R * R convolutions.
R = 2
D = R + R + 1
CIRCLE = Vips::Image.black(D, D).draw_circle(1, R, R, R, fill: true).to_a
new_image = image
D.times do |i|
D.times do |j|
next unless CIRCLE[i][j] == [1]
t = image.conv Vips::Image.new_from_array Array.new(D){ [0]*D }.tap{ |t| t[i][j] = 1 }
new_image = (new_image > t).ifthenelse(new_image, t)
end
end
return new_image
If you don't mind a square window, you can do this with a rank filter:
result = image.rank w, h, w * h - 1
http://jcupitt.github.io/libvips/API/current/libvips-morphology.html#vips-rank
http://www.rubydoc.info/gems/ruby-vips/Vips/Image#rank-instance_method
Where w
and h
are the width and height of the window.
Of course, max/min are separable, so you could also write this as:
result = image.rank(w, 1, w - 1).rank(1, h, h - 1)
which would be much faster for a large radius.