Byte-Scaling
The data values of some images may be greater than 255. When displayed with the TV routine or the IDLgrImage object, the data values above 255 are wrapped around the range of 0 to 255. This type of display may produce discontinuities in the resulting image.
The display can be changed to not wrap around and appear more linear by byte-scaling the image. The scaling process is linear with the minimum data value scaled to 0 and the maximum data value scaled to 255. You can use the BYTSCL function to perform this scaling process.
If the range of the pixel values within an image is less than 0 to 255, you can use the BYTSCL function to increase the range from 0 to 255. This change will increase the contrast within the image by increasing the brightness of darker regions. Keywords to the BYTSCL function also allow you to decrease contrast by setting the highest value of the image to less than 255.
Note
The BYTSCL function usually results in a different data type (byte) and range (0 to 255) from the original input data. When converting data with BYTSCL for display purposes, you may want to keep your original data as a separate variable for statistical and numerical analysis.
The following example shows how to use the BYTSCL function to scale data with values greater than 255, producing a more uniform display. This example uses a Magnetic Resonance Image (MRI) of a human brain within the mr_brain.dcm file in the examples/data directory. The values of this data are unsigned integer and range from 0 to about 800. Complete the following steps for a detailed description of the process.
Example Code
See bytescaling.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering bytescaling at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT bytescaling.pro.
- Import the image from the
mr_brain.dcmfile: - Initialize the display:
- Create a window and display the original image:
- Byte-scale the image:
- Create another window and display the byte-scaled image:
file = FILEPATH('mr_brain.dcm', $
SUBDIRECTORY = ['examples', 'data'])
image = READ_DICOM(file)
imageSize = SIZE(image, /DIMENSIONS)
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, imageThe following figure shows the original image.
The following figure shows the result of byte-scaling. Unlike the original image, the byte-scaled image accurately represents the maximum and minimum pixel values by linearly adjusting the range for display.

