4.3 Image Manipulation 41
Listing 4.1 Definitions of variables in code examples.
1 integer s[][]: Source Image, a 2−d array
2 integer source width : width of source image
3 integer source height: height of source image
4 real sminx: minimum horizontal map coordinate of source image
5 real sminy: minimum vertical map coordinate of source image
6 real smaxx: maximum horizontal map coordinate of source image
7 real smaxy: maximum vertical map coordinate of source image
8
9 integer t [][]: Target Image, a 2−d array
10 integer target width : width of target image
11 integer target height : height of target image
12 real tminx : minimum horizontal map coordinate of target image
13 real tminy: minimum vertical map coordinate of target image
14 real tmaxx: maximum horizontal map coordinate of target image
15 real tmaxy: maximum vertical map coordinate of target image
Listing 4.2 Definition of abstract function interpolate that will be implemented by specific algo-
rithms.
1 function integer interpolate (s , sminx , sminy , smaxx, smaxy , source width ,
source height , tx , ty)
Listing 4.3 Compute the geographic coordinates of the center of a pixel.
1 function real , real geolocate ( real minx ,miny ,maxx,maxy, integer i , j ,width , height
)
2 comment :
3 minx ,miny ,maxx,maxy are the geographical coordinates of the image
4 width and height are the dimensions of the image
5 i and j are the pixel coordinates to be converted to geographic
coordinates
6
7 real pixel width= (maxx−minx ) / width
8 real pixel height= (maxy−miny) / height
9
10 real x =(i + 0.5) ∗ pixel width + minx
11
12 int adj j = height − j − 1
13
14 real y =(adj j + 0.5) ∗ pixel height + miny
15
16 comment: we offset by 0.5 the indexes , to get the center of the pixel
17
18 return x,y
dinates but different dimensions. So, sminx = tminx, miny = tminy, smaxx
= tmaxx,andsmaxy = ymaxy,butsource_width = target_width and
source_height = target_height.
Care should be taken in determining whether to iterate in row-major or column-
major order. This is a practical consideration that must be made in the context of
specific programming environments. Java, C, and many others store array data in
row-major format . Iterating in this fashion can potentially greatly improve the per-
formance of the algorithm due to the principle of Locality of Reference. In the con-