Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

magnitude and direction

Asked by munch kitty on 6 Feb 2012
Latest activity Edited by Kaustubha Govind on 4 Oct 2013

how to calculate the magnitude and direction value of the images in matlab?(code)


Qura on 29 Mar 2013

Hi! I want to construct histogram of gradient magnitude and gradient direction for each image gradient.angle are quantized by 45 Please help

Walter Roberson on 29 Mar 2013

Please start a new Question for this problem.

munch kitty



No products are associated with this question.

2 Answers

Answer by Junaid on 6 Feb 2012

I think you want to compute the SIFT right ?

Anyway to divide the image into blocks, you can use following tip

in case you have difficulty you can share your code.

To find the gradient magnitude and orientation, the following code may help you.

angle = 360;
[GradientX,GradientY] = gradient(double(img));
    Gr = sqrt((GradientX.*GradientX)+(GradientY.*GradientY));
    index = GradientX == 0;
    GradientX(index) = 1e-5;
     YX = GradientY./GradientX;
      A = ((atan2(GradientY,GradientX)+pi)*180)/pi; 

A contains the orientation of each pixel.


munch kitty on 8 Feb 2012

junaki..the image block was posted above.for taht 12 blocks i have to calculate magnitude and orientation

mano on 8 Feb 2012

i found the gradient and magnitude but i want to how to found gradient magnitude histogram?if u know help me

Lee on 25 Mar 2013

Hi Junaid, may I know why parameter YX is calculated?

Answer by Junaid on 6 Feb 2012

what do you mean by direction of images. I hope you are talking about gradient value and direction (orientation) ?


munch kitty on 6 Feb 2012

yes absolutely.but the mag and dir value when we printed it shows for each pixel.i want the values for block by block.

Rupali on 6 Feb 2012

i want to know how to divide image into blocks ????????

munch kitty on 8 Feb 2012

a=imread('image004.png'); a1=imresize(a,[300,340]);
ck1=1; cblock(:,:,:,1)=a1(1:100,1:100,:);
for ci1=1:3
for cj1=1:3
row1=80 ;
cblock(:,:,:,ck1)=a1( (cbs*(ci1-1)+1:cbs*(ci1-1)+cbs), ((row1+1)+(cj1-1)*80:row2+(cj1-1)*80),:);

we divide the image into 3X4.overlap of some pixels..u can also do non overlapping..


Contact us