timholy/Images.jl — pull request #134 by kmsquire (2014-07-26 02:59:37+00:00)
Title: WIP: imedge/gradient operator updates

I'm doing edge detection for a project, and the current `imedge` implementation seemed to have a few small issues:

* Magnitude and phase were always returned as matrices, even with `Image` inputs.
* The gradient calculation returned the negative gradient.
* `imedge` always calculated returned the magnitude and phase, even if they weren't needed.

This PR addresses the above points, and adds a few things:

* Refactor `imedge` into `imgradientxy`, `imgradient`; (`imedge` still exists)
* Add versions of `sqrt`, `tan2` and unary `(-)` which return `Images` with `Image` input, so that magnitude and phase can be returned as `Image` types
* Added additional gradient operators (`"shigeru3"`, `"shigeru4"`, `"shigeru5"`) from Ando Shigeru
(Consistent Gradient Operators, PAMI Vol 22 No 3, March 2000)
* Set `shigeru3` as default gradient method for `imgradient`, `imgradientxy`
* Changed Sobel, Prewitt operators to give gradient instead of negative gradient; also changed the order of arguments to return horizontal filter, vertical filter
* Added separable approximations of `shigeru4` and `shigeru5` filters (`"shigeru4_sep"` and `"shigeru5_sep"`)
* Generalized `imgradient*` and `imedge` functions to >2D

----------------------

Notes:
* The Shigeru filters are nice in that they give a close approximation to the true (sampled) gradient than Sobel or Prewitt, so it made sense to use one of them as the default method for the `imgradient*` methods.
* The changes to the `sobel` and `prewitt` functions are technically breaking changes. I thought it made more sense to be consistent with the ordering in the `imgradient*` functions (and `imread`), but I can change the return value order back if you'd like (and change the new filters to match).
* I copied the filter values for the `shigeru*` filters directly from the paper. As such, they have limited precision, and `shigeru4` and `shigeru5` are not separable, which causes `imfilter` to call `imfilter_inseparable`. Unfortunately, `imfilter_inseparable` does not respect `Image` file inputs, so the return values are always `Arrays` (filed as #133). Because of this, I created the separable versions of `shigeru4` and `shigeru5`. (The original filters are **almost** separable, so it might be that calculating precise filter values would help, but that's unclear at this time.)
* Because the y-axis increases going down, the call to `tan2` requires flipping the sign of `grad_y` on the (which creates a copy of `grad_y` and is inefficient).

To do:
- [ ] Add tests
- [ ] Update docs
- [ ] Fix gradient calculation so it does not call `-grad_y`

Feedback appreciated!