A fast way to compute gradient information
3 views (last 30 days)
Show older comments
Hello everybody,
I am doing image registration and for one of my metrics and I need to use gradient information beteween two images, but it is very slow to compute (I tried to resize my images but it is still very slow).
I don't know if it is because there is an error in my code or because it is not optimized (of course it is not since I use a for loop for my third step).
My problem: we have two images (I and J) to register (they are not the same size, I>J)
- 1st step: we crop a part of I to the size of J
- 2nd step: we compute the gradient information
- 3rd step: we translate I of 1 pixel(to the right or to the bottom, depends in where we are on the picture ) and we restart from the begining until J has "browsed" every part of I.
Here is my code for the second step:
function GI=GI_1(I,J)
%gradients' magnitude and direction
[Gmag_I, Gdir_I] = imgradient(I);
[Gmag_J, Gdir_J]=imgradient(J);
[a,b]=size(I);
%angle between the two gradients
theta_tab=Gdir_I-Gdir_J;
%making the gradients of same direction more visible
theta_tab=0.5*(cosd(2*theta_tab)+1)
%gradients
gradient_I=imgradient(I);
gradient_J=imgradient(J);
min_norm=min(norm(gradient_I), norm(gradient_J));
min_multi=theta_tab*min_norm;
GI=sum(min_multi(:));
end
The third step is basically a for loop such as this one (I know it is a little bit messy but I think we get the main idea):
im_crop=I;
for i=1:x+10
im_trans=imtranslate(im_crop, [0 -1]);
for j=1:z+10
im_crop=im_trans;
im_crop=imtranslate(im_crop, [-j 0]);
rect3=[0 0 (rect2(3)+1)*scale (rect2(4)+1)*scale];
im_crop2 = imcrop(im_crop, rect3);
GI=GI_1(im_crop2,J);
GI_tab(j,i)=GI;
end
im_crop=im_trans;
end
There you go, don't hesitate to ask any question. I hope somebody will have a solution. Thanks in advance, have a nice day!
0 Comments
Answers (0)
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!