28

Aug

2016

### Upsampling images using a Lagrange polynomial method

**function**

**lanczos**, data

**3**:

**3**:

**.25**]

**3***

**sin**(

**!pi***xval)*(

**sin**(

**!pi***xval/

**3d**)/

**!pi**/

**!pi**/xval/xval)

**where**(xval

**eq**

**0**)] =

**1**

**fltarr**(data.

*dim**

**4**)

**0**:*:

**4**,

**0**:*:

**4**] = data

**convol**(msk, l2d, /edge_trunc)

**byte**(

**round**(hi>

**0**<

**255**))

**return**, hi

**end**

**function**

**lagrange**, a, x, y

**compile_opt**idl2, logical_predicate

**floor**(x)

**floor**(y)

**1**,

**0**,

**1**,

**2**]

**replicate**(

**0.**,

**size**(x, /DIM))

**replicate**(

**1.**, [

**size**(x1, /DIM),

**4**])

**replicate**(

**1.**, [

**size**(x1, /DIM),

**4**])

**for**i=

**0**,

**3**

**do**

**begin**

**for**j=

**0**,

**3**

**do**

**begin**

**if**i

**ne**j

**then**

**begin**

**endif**

**endfor**

**endfor**

**for**i=

**0**,

**3**

**do**

**begin**

**for**j=

**0**,

**3**

**do**

**begin**

**endfor**

**endfor**

**return**, retval

**end**

**pro**

**upsample_example**

**compile_opt**idl2,logical_predicate

**filepath**('moon_landing.png', subdir=['examples','data'])

**read_png**(f)

*dim*

**window**, xsize=dim[

**0**], ysize=dim[

**1**],

**0**, title='Original full size'

**tv**, data

**120**

**105**

**60**

**100**

**window**, xsize=

**4***dx, ysize=

**4***dy,

**1**, title='CONGRID pixel-replication'

**tv**,

**congrid**(data[xs:xs+dx-

**1**,ys:ys+dy-

**1**],

**4***dx,

**4***dy)

**write_png**,'moon-pixel-replication.png',

**tvrd**()

**window**, xsize=

**4***dx, ysize=

**4***dy,

**2**, title='CONGRID linear'

**tv**,

**congrid**(data[xs:xs+dx-

**1**,ys:ys+dy-

**1**],

**4***dx,

**4***dy,/interp)

**write_png**,'moon-bilinear.png',

**tvrd**()

**window**, xsize=

**4***dx, ysize=

**4***dy,

**3**, title='Lanczos'

**tv**, (

**lanczos**(data))[xs*

**4**:xs*

**4**+dx*

**4**-

**1**,ys*

**4**:ys*

**4**+dy*

**4**-

**1**]

**write_png**,'moon-lanczos.png',

**tvrd**()

**window**, xsize=

**4***dx, ysize=

**4***dy,

**4**, title='Lagrange'

**float**(xs):xs+dx:

**0.25**]

**float**(ys):ys+dy:

**0.25**]

**tv**,

**byte**(

**lagrange**(

**float**(data), $

**replicate**(

**1**,

**1**,ycoord.

*length*), $

**replicate**(

**1**,xcoord.

*length*) # ycoord)>

**0**<

**255**)

**write_png**,'moon-lagrange.png',

**tvrd**()

**end**

Bi-linear interpolation

Lanczos resampling

Lagrange resampling

Categories: IDL Blog | IDL Data Point