Imgradients not defined

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:

      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:

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!

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

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?

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.

Instead of

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

perhaps you should have

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).

1 Like

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.