# Imgradients not defined

**URL:** <https://discourse.julialang.org/t/imgradients-not-defined/18470>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 8, 2018, 9:05pm UTC](https://discourse.julialang.org/t/imgradients-not-defined/18470 "2018-12-08T21:05:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shane-segal](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@shane-segal](https://discourse.julialang.org/u/shane-segal)\
**Post date:** [December 8, 2018, 9:05pm UTC](https://discourse.julialang.org/t/imgradients-not-defined/18470/1 "2018-12-08T21:05:32Z")

</div>

Hi all,

I’m just starting out with Julia, and I’m reimplementing a seam carving application I originally implemented in Matlab. I’m trying to compute my image gradients using:

```julia
      gx, gy = imgradients(img, kernelfun=ando3, border="replicate")

```

I’ve also tried explicitly using `kernelfun=Kernel.ando3` and `KernelFactors.ando3` but both of those give me an `UndefVarError` as well.

My main issue is that when I try and use `imgradients` in any fashion, I will either get an `UndefVarError` for the imgradients function or for the kernel function I am passing in. I believe I am importing the required packages correctly as well.

The top of my file has this `using` line:

```julia
using Images, ImageView, LinearAlgebra;

```

I believe that should be all I need. Is there anything obvious I would be missing?

I’ve also been looking at the source for imgradients and I can see that I am matching the type signature of the call, adding to my confusion.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 8, 2018, 9:24pm UTC](https://discourse.julialang.org/t/imgradients-not-defined/18470/2 "2018-12-08T21:24:59Z")

</div>

Can you please post the full error message you get, including the stacktrace? That will make it much easier for us to help you.

---

<div class="post-metadata">

**Author:** ![shane-segal](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@shane-segal](https://discourse.julialang.org/u/shane-segal)\
**Post date:** [December 9, 2018, 1:18am UTC](https://discourse.julialang.org/t/imgradients-not-defined/18470/3 "2018-12-09T01:18:24Z")

</div>

I’ve actually solved my problem, I had my code in a module, but I had the `Using`’s outside of the module, as you would if you were creating a class in most other languages.

Thanks for the help anyways! Is there a way for me to close this topic as answered, or is that up to the moderators?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 9, 2018, 12:17pm UTC](https://discourse.julialang.org/t/imgradients-not-defined/18470/4 "2018-12-09T12:17:34Z")

</div>

It’s marked as solved, so I think you’re all set. There’s no need to remove the post, as it may be helpful to others in the future.

---

<div class="post-metadata">

**Author:** ![zygmuntszpak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zygmuntszpak/32/2591_2.png) [@zygmuntszpak](https://discourse.julialang.org/u/zygmuntszpak)\
**Post date:** [December 10, 2018, 9:51am UTC](https://discourse.julialang.org/t/imgradients-not-defined/18470/5 "2018-12-10T09:51:08Z")

</div>

Instead of

```julia
      gx, gy = imgradients(img, kernelfun=ando3, border="replicate")

```

perhaps you should have

```julia
gy, gx = imgradients(...

```

That is, the gradients are computed across the first and then second dimension of the image (I.e. the rows and then the columns).

---

<div class="post-metadata">

**Author:** ![shane-segal](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@shane-segal](https://discourse.julialang.org/u/shane-segal)\
**Post date:** [December 12, 2018, 5:40am UTC](https://discourse.julialang.org/t/imgradients-not-defined/18470/6 "2018-12-12T05:40:24Z")

</div>

Yeah, I saw this a little while after. Thankfully I was just computing the gradient magnitude so it wasn’t harmful. It’s a mistake I make somewhat too often.
