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

Thread Subject:
faster loop processing

Subject: faster loop processing

From: Michael Lonther

Date: 17 May, 2008 21:08:02

Message: 1 of 2

Hello All,

I am trying to resample an image with the following code.
However, it is taking a long time because of the nested
loop. Is it possible to make this go faster? The
geog2pixel function (not provided here) simply finds the
pixel location given latitude and longitude.

Thanks...

fid = fopen('foo.bin','rb');
fpar = fread(fid,'char');
fclose(fid);
clear fid;

fpar = reshape(fpar,10800,5400);
out = zeros(4320,2160);

lonn = -179.9583333:0.083333:179.9583333;
latt = 89.9583333:-0.083333:-89.9583333;

for x = 1:4320
    for y = 1:2160
        [xx,yy] = geog2pixel(latt(y),lonn(x));
        out(x,y) = fpar(xx,yy);
        clear xx yy;
    end
end

Subject: faster loop processing

From: Peter Boettcher

Date: 17 May, 2008 21:23:43

Message: 2 of 2

"Michael Lonther" <rsbu@yahoo.com> writes:

> Hello All,
>
> I am trying to resample an image with the following code.
> However, it is taking a long time because of the nested
> loop. Is it possible to make this go faster? The
> geog2pixel function (not provided here) simply finds the
> pixel location given latitude and longitude.
>
> Thanks...
>
> fid = fopen('foo.bin','rb');
> fpar = fread(fid,'char');
> fclose(fid);
> clear fid;
>
> fpar = reshape(fpar,10800,5400);
> out = zeros(4320,2160);
>
> lonn = -179.9583333:0.083333:179.9583333;
> latt = 89.9583333:-0.083333:-89.9583333;
>
> for x = 1:4320
> for y = 1:2160
> [xx,yy] = geog2pixel(latt(y),lonn(x));
> out(x,y) = fpar(xx,yy);
> clear xx yy;
> end
> end

First, vectorize geog2pixel, so you can pass in entire matrices for the
transform. Then, use interp2 to perform the resampling. If you're happy
with nearest-neighbor, be sure to specify that as your interpolation
method, otherwise bilinear will be used.

-Peter

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us