Main Content

matlab.io.fits.setBscale

Set FITS image scaling

Syntax

matlab.io.fits.setBscale(fptr,bscale,bzero)

Description

matlab.io.fits.setBscale(fptr,bscale,bzero) sets the scaling factors for the primary array or image extension of the specified FITS file. When you read data from the primary image array or image extension, the retrieved data is automatically scaled according to this equation:

readData = bscale*storedData + bzero

When you write data to the primary image array or image extension, the written data is automatically scaled according to the inverse equation:

writtenData = (specifiedData – bzero)/bscale

This function affects only the automatic scaling performed when the file data is read or written. The function does not change the BSCALE or BZERO keyword values.

Examples

collapse all

Open a sample FITS file, and read some image data from it.

import matlab.io.*
fptr = fits.openFile("tst0012.fits");
data = fits.readImg(fptr);
data(1:5,1:5)
ans = 5×5 single matrix

  135.2000  134.9436  134.1752  132.8980  131.1165
  135.2000  134.9436  134.1752  132.8980  131.1165
  135.2000  134.9436  134.1752  132.8980  131.1165
  135.2000  134.9436  134.1752  132.8980  131.1165
  135.2000  134.9436  134.1752  132.8980  131.1165

Set the bscale and bzero scaling factors to 2 and 0.5, respectively, and then reread the image data. The data is scaled.

fits.setBscale(fptr,2,0.5)
data_scaled = fits.readImg(fptr);
data_scaled(1:5,1:5)
ans = 5×5 single matrix

  270.9000  270.3871  268.8505  266.2959  262.7331
  270.9000  270.3871  268.8505  266.2959  262.7331
  270.9000  270.3871  268.8505  266.2959  262.7331
  270.9000  270.3871  268.8505  266.2959  262.7331
  270.9000  270.3871  268.8505  266.2959  262.7331

Close the file.

fits.closeFile(fptr)

Tips

  • This function corresponds to the fits_set_bscale (ffpscl) function in the CFITSIO library C API.

  • To use this function, you must be familiar with the CFITSIO C interface. You can access the CFITSIO documentation at the CFITSIO website.

Extended Capabilities

expand all

Version History

expand all