Parfor with double loop - improving more speed

Hello everybody,
I'm trying to develop an photogrammetric program to generate an image without camera distortions using the equations bellow in a double loop (rows by columns):
clc clear
Cx = 7760/2.0; Cy = 10328/2.0; res_pixel = 5.2/1000.0;
x0 = -0.125000;
y0 = 0.120000;
k0 = 2.8651e-007;
k1 = -2.3991e-005;
k2 = 1.1672e-008;
k3 = -1.1518e-016;
p1 = -1.3960e-006;
p2 = -1.7870e-007;
IMG1 = imread('c:\temp\24_4855.tif');
[x1,y1,z1] = size(IMG1);
S = uint8(zeros(x1,y1,z1));
for i=1:x1
for j=1:y1
x = res_pixel*((i-1)-Cx);
y = -res_pixel*((j-1)-Cy);
%Radial distortion k0,k1,k2,k3
r = sqrt((x^2)+(y^2));
drad_x = (k0+(k1*r^2)+(k2*r^4)+(k3*r^6))*x;
drad_y = (k0+(k1*r^2)+(k2*r^4)+(k3*r^6))*y;
%Decentering distortion p1,p2
ddesc_x = p1*(r^2+(2*x^2))+2*p2*x*y;
ddesc_y = p2*(r^2+(2*y^2))+2*p1*x*y;
%Coordinates with distortions
x_dist = x + x0 + drad_x + ddesc_x;
y_dist = y + y0 + drad_y + ddesc_y;
%Coordinates with distortions - double
c1 = ((x_dist/res_pixel)+Cx)+1;
l1 = ((-1*(y_dist/res_pixel))+Cy)+1;
%Coordinates with distortions - int
c2 = fix(((x_dist/res_pixel)+Cx)+1);
l2 = fix(((-1*(y_dist/res_pixel))+Cy)+1);
%Bilinear interpolation:
dx1 = double(c1 - c2);
dy1 = double(l1 - l2);
a1 = double(IMG1(c2,l2,:));
a2 = double(IMG1(c2+1,l2,:));
a3 = double(IMG1(c2,l2+1,:));
a4 = double(IMG1(c2+1,l2+1,:));
RGB = uint8(a1 + (dx1*(a2 - a1)) + (dy1*(a3 - a1)) +
(dx1*dy1*(a1 - a2 - a3 + a4)));
Image matrix:
S(i,j,:) = RGB;
end
end
When I test a simple double loop (without any equation) and using an image with the dimensions: x1 = 10328 and y1 = 7760, the elapsed time is 12.159344 seconds. However, when I test the double loop (with all equations) with the same image and using "parfor", the elapsed time is aprox. 1200 seconds. I'm using an computer with i7 processor and 8Gb memory.
Any suggestion how I can reduce the processing time?
Thanks and Regards,
Leo.

Answers (0)

Categories

Asked:

on 19 Mar 2017

Community Treasure Hunt

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

Start Hunting!