|
Image Processing : Transforming Image Geometry |
|
Image padding introduces new pixels around the edges of an image. The border provides space for annotations or acts as a boundary when using advanced filtering techniques.
This exercise adds a 10-pixel border to left, right and bottom of the image and a 30-pixel border at the top allowing space for annotation. The diagonal lines in the following image represent the area that will be added to the original image. For an example of padding an image, complete the following steps.
| Example Code See paddedimage.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
To add a border around the earth image, complete the following steps:
earth = READ_PNG(FILEPATH('avhrr.png', $
SUBDIRECTORY = ['examples', 'data']), R, G, B)
DEVICE, DECOMPOSED = 0, RETAIN = 2
TVLCT, R, G, B maxColor = !D.TABLE_SIZE - 1 TVLCT, 255, 255, 255, maxColor
earthSize = SIZE(earth, /DIMENSIONS)
Using the REPLICATE syntax, Result = REPLICATE (Value, D1 [, ..., D8]), create an array of the specified dimensions, and set Value equal to the byte value of the final color index to make the white border:
paddedEarth = REPLICATE(BYTE(maxColor), earthSize[0] + 20, $ earthSize[1] + 40)
| Note The argument BYTE(maxColor) in the previous line produces a white background only when white is designated as the final index value for the red, green and blue bands of the color table you are using. As shown in step 3, this can be accomplished by setting each color component (of the color table entry indexed by maxColor) to 255. See Graphic Display Essentials for detailed information about modifying color tables. |
paddedEarth [10,10] = earth
WINDOW, 0, XSIZE = earthSize[0] + 20, $ YSIZE = earthSize[1] + 40
TV, paddedEarth
x = (earthSize[0]/2) + 10 y = earthSize[1] + 15 XYOUTS, x, y, 'World Map', ALIGNMENT = 0.5, COLOR = 0, $ /DEVICE
The resulting image should appear similar to the following figure.
IDL Online Help (March 06, 2007)