How to get the gradient of a pixel in an image?

I am doing block processing on a fingeprint image and I will like to get the gradient of all the pixels in their x and y components separately using a sobel filter. I am doing this block by block.
I saw the function imgradient() but after reading the documentation it seems to be getting the gradient for the whole image that is passed to it, which in my case will be the block, except i understood wrongly, and if i did please help me out or is there any function i can use to get the gradient of just one pixel in the image block.

 Accepted Answer

imgradient() gets the gradient at every pixel, for every pixel in the image. The gradient cannot be computed from a single pixel because you need neighboring pixels to determine the slope and direction. Let's say you had one single pixel and it's value is 50. So what is it's gradient? It does not have a gradient because it has no neighbors and thus no slope from there to anywhere else.
If you want, you can call imgradient() on a whole image, or on a sub-image (block). It does not make sense to get the gradient of just one pixel, like I said. You get the gradient for a bunch of pixels and every pixels will have a gradient value associated with it that was determined by looking at neighboring pixels.

8 Comments

I understand better now, but in the paper i used it tells me to calculate the gradient of all the pixels in a sub block, can imgradient help calculate all the pixels or is it ging to give me just one gradient value?
I think I've understood how the imgradient() function works now, please correct me if i'm wrong but it outputs two matrices, one for the magnitude of every pixel and the other for the angle of the gradient of every pixel.
So is it correct if i want to get the angle and magnitude of a pixle gradient that i just collect these two values from the two matrices at the same location?
Secondly, please i want to use blockproc() function to do the processing how will i use it?. I don't seem to understand how to pass a function that is well written to it and I don't understand what the blockproc() function returns.
The picture here is what I am trying to achieve and i have also seen that i should use the quiver function to draw the arrows, please how will i do this also.
Thanks
Yes, the gradient is a vector with both amplitude and direction. I'm not sure what your paper says to do with those. I imagine you'd want a direction 90 degrees perpendicular to the ridges. Anyway, I'm attaching several blockproc demos that you can study. They're well commented.
Thanks a lot Image Analyst, I will go through the blockproc files you sent, I'm sure i should understand it after.
Please i also need help on the quiver function, I am going to get the average gradient of a block in the image but i don't know how to draw the arrow using the average gradient data in that block with the quiver() function.
Please i need help on that.
Thanks
I haven't ever used quiver so I don't know any more about it than you do.
Oh okay, thanks then. I really appreciate the time you took to help. God bless.
I tried reading the coede you sent but i didnt understand it. Please check out this question.
Thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!