Asked by munch kitty
on 6 Feb 2012

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

*No products are associated with this question.*

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

http://mathworks.com/matlabcentral/answers/24104-image-separation-into-blocks

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

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

munch kitty
on 8 Feb 2012

cbs=100;

ck1=1; cblock(:,:,:,1)=a1(1:100,1:100,:);

cblock(:,:,:,5)=a1(101:200,1:100,:);

cblock(:,:,:,9)=a1(201:300,1:100,:);

for ci1=1:3

ck1=ck1+1;

for cj1=1:3

row1=80 ;

row2=180;

cblock(:,:,:,ck1)=a1( (cbs*(ci1-1)+1:cbs*(ci1-1)+cbs), ((row1+1)+(cj1-1)*80:row2+(cj1-1)*80),:);

ck1=ck1+1;

end

end

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

Opportunities for recent engineering grads.

## 2 Comments

## Qura (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/28166#comment_139728

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 (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/28166#comment_139730

Please start a new Question for this problem.