Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
24
Добавлен:
09.02.2015
Размер:
673.28 Кб
Скачать

Interleave: The format in which the data is stored. This can be

either 'bsq','bil', or 'bip' for Band-Sequential,

Band-Interleaved-by-Line or Band-Interleaved-by-Pixel respectively.

BYTEORDER: The byte ordering (machine format) in which the data is

stored. This can be 'ieee-le' for little-endian or 'ieee-be' for

big-endian. All other machine formats described in the help for FOPEN

are also valid values for BYTEORDER.

SUBSET: (optional) A cell array containing either {DIM,INDEX} or

{DIM,METHOD,INDEX}. DIM is one of three strings: 'Column', 'Row', or

'Band' specifying which dimension to subset along. METHOD is 'Direct'

or 'Range'. If METHOD is omitted, then the default is 'Direct'. If

using 'Direct' subsetting, INDEX is a vector specifying the indices to

read along the Band dimension. If METHOD is 'Range', INDEX is a 2 or

3 element vector of [START, INCREMENT, STOP] specifying the range and

step size to read along the dimension. If INDEX is 2 elements, then

INCREMENT is assumed to be one.

Examples:

% Setup initial parameters for a dataset.

rows=3; cols=3; bands=5;

filename = tempname;

% Define the dataset.

fid = fopen(filename, 'w', 'ieee-le');

fwrite(fid, 1:rows*cols*bands, 'double');

fclose(fid);

% Read the every other band of the data using the Band-Sequential format.

im1 = multibandread(filename, [rows cols bands], ...

'double', 0, 'bsq', 'ieee-le', ...

{'Band', 'Range', [1 2 bands]} )

% Read the first two rows and columns of data using

% Band-Interleaved-by-Pixel format.

im2 = multibandread(filename, [rows cols bands], ...

'double', 0, 'bip', 'ieee-le', ...

{'Row', 'Range', [1 2]}, ...

{'Column', 'Range', [1 2]} )

% Read the data using Band-Interleaved-by-Line format.

im3 = multibandread(filename, [rows cols bands], ...

'double', 0, 'bil', 'ieee-le')

% Delete the file that we created.

delete(filename);

% The FITS file 'tst0012.fits' contains int16 BIL data starting at

% byte 74880.

im4 = multibandread( 'tst0012.fits', [31 73 5], ...

'int16', 74880, 'bil', 'ieee-be', ...

{'Band', 'Range', [1 3]} );

im5 = double(im4)/max(max(max(im4)));

imagesc(im5);

See also fread, fwrite, imread, memmapfile, multibandwrite.

Reference page in Help browser

doc multibandread

<multibandwrite> - Write multiband data to a file.

MULTIBANDWRITE write multiband data to a file

MULTIBANDWRITE writes a three dimensional data set to a binary file. All the

data may be written to the file with one function call or MULTIBANDWRITE may

be called repeatedly to write pieces of the complete data set to the file.

The following two syntaxes are ways to use MULTIBANDWRITE to write the

entire data set to the file with one function call. The optional

parameter/value pairs described at the below can also be used with these

syntaxes.

MULTIBANDWRITE(DATA,FILENAME,INTERLEAVE) writes DATA, the 2 or

3-dimensional array of any numeric or logical type, to the binary file

FILENAME. The bands are written to the file in the form specified by

INTERLEAVE. The length of the third dimension of DATA is equal to the

number of bands. By default the data is written to the file in the same

precision as it is stored in MATLAB (the same as the class of DATA).

INTERLEAVE is a string specifying the method of interleaving the bands

written to the file. Valid strings are 'bil', 'bip', 'bsq', representing

band-interleaved-by-line, band-interleaved-by-pixel, and band-sequential

respectively. INTERLEAVE is irrelevant if DATA is 2-dimensional. If

FILENAME already exists, it will be overwritten unless the optional OFFSET

parameter has been specified.

The complete data set may be written to the file in smaller chunks by

making multiple calls to MULTIBANDWRITE using the following syntax.

MULTIBANDWRITE(DATA,FILENAME,INTERLEAVE,START,TOTALSIZE) writes

the data to the binary file piece by piece. DATA is a subset of the

complete data set. MULTIBANDWRITE will be called multiple times to write

all the data to the file. A complete file will be written during the

first function call and populated with fill values outside the subset

provided in the first call and subsequent calls will overwrite all or

some of the fill values. The parameters FILENAME, INTERLEAVE, OFFSET

and TOTALSIZE should remain constant throughout the writing of the

file.

START == [firstrow firstcolumn firstband] is 1-by-3 where firstrow

and firstcolumn gives the image pixel location of the upper left

pixel in the box and firstband gives the index of the first band to

write. DATA contains some of the data for some of the bands.

DATA(I,J,K) contains the data for the pixel at [firstrow + I - 1,

firstcolumn + J - 1] in the (firstband + K - 1)-th band.

TOTALSIZE == [totalrows,totalcolumns,totalbands] gives the full

three-dimensional size of the complete data set to be contained in

the file.

Any number and combination these optional parameter/value pairs may be

added to the end of any of the above syntaxes.

MULTIBANDWRITE(DATA,FILENAME,INTERLEAVE,...,PARAM,VALUE,...)

Parameter Value Pairs:

PRECISION is a string to control the form and size of each element

written to the file. See the help for FWRITE for a list of valid

values for PRECISION. The default precision is the class of the data.

OFFSET is the number of bytes to skip before the first data element. If

the file does not already exist, ASCII null values will be written to fill

the space by default. This option is useful when writing a header to the

file before or after writing the data. When writing the header after the

data is written, the file should be opened with FOPEN using 'r+'

permission.

MACHFMT is a string to control the format in which the data

is written to the file. Typical values are 'ieee-le' for little endian

and 'ieee-be' for big endian however all values for MACHINEFORMAT as

documented in FOPEN are valid. See FOPEN for a complete list. The

default machine format is the local machine format.

FILLVALUE is a number specifying the value for missing data. FILLVALUE

may be a single number, specifying the fill value for all missing data

or FILLVALUE may be a 1-by-number of bands vector of numbers

specifying the fill value for each band. This value will be used to

fill space when data is written in chunks.

Examples:

% 1. Write all data (interleaved by line) to the file in one call.

data = reshape(uint16(1:600), [10 20 3]);

multibandwrite(data,'data.bil','bil');

% 2. Write the bands (interleaved by pixel) to the file in

% separate calls.

totalRows = size(data, 1);

totalColumns = size(data, 2);

totalBands = size(data, 3);

for i = 1:totalBands

bandData = data(:, :, i);

multibandwrite(bandData, 'data.bip', 'bip', [1 1 i],...

[totalColumns, totalRows, totalBands]);

end

% 3. Write a single-band tiled image with one call for each tile.

% This is useful if only a subset of each band is available

% at each call to MULTIBANDWRITE.

numBands = 1;

dataDims = [1024 1024 numBands];

data = reshape(uint32(1:(1024 * 1024 * numBands)), dataDims);

for band = 1:numBands

for row = 1:2

for col = 1:2

subsetRows = ((row - 1) * 512 + 1):(row * 512);

subsetCols = ((col - 1) * 512 + 1):(col * 512);

upperLeft = [subsetRows(1), subsetCols(1), band];

multibandwrite(data(subsetRows, subsetCols, band), ...

'banddata.bsq', 'bsq', upperLeft, dataDims);

end

end

end

See also multibandread, fwrite, fread

Reference page in Help browser

doc multibandwrite

Соседние файлы в папке Библиотеки Matlab