Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pmi432 / LR07 / 2read / image processing toolbox guide.pdf
Скачиваний:
150
Добавлен:
18.03.2015
Размер:
18.08 Mб
Скачать

Performing Distinct Block Operations

Block Size and Performance

When using the blockproc function to either read or write image files, the number of times the file is accessed can significantly affect performance. In general, selecting larger block sizes reduces the number of times blockproc has to access the disk, at the cost of using more memory to process each block. Knowing the file format layout on disk can help you select block sizes that minimize the number of times the disk is accessed. See the blockproc reference page for more information about file formats.

TIFF Image Characteristics

TIFF images organize their data on disk in one of two ways: in tiles or in strips. A tiled TIFF image stores rectangular blocks of data contiguously in the file. Each tile is read and written as a single unit. TIFF images with strip layout have data stored in strips; each strip spans the entire width of the image and is one or more rows in height. Like a tile, each strip is stored, read, and written as a single unit.

When selecting an appropriate block size for TIFF image processing, understanding the organization of your TIFF image is important. To find out whether your image is organized in tiles or strips, use the imfinfo function.

The struct returned by imfinfo for TIFF images contains the fields TileWidth and TileLength. If these fields have valid (nonempty) values, then the image is a tiled TIFF, and these fields define the size of each tile. If these fields contain values of empty ([]), then the TIFF is organized in strips. For TIFFs with strip layout, refer to the struct field RowsPerStrip, which defines the size of each strip of data.

When reading TIFF images, the minimum amount of data that can be read is a single tile or a single strip, depending on the type of TIFF. To optimize the performance of blockproc, select block sizes that correspond closely with how your TIFF image is organized on disk. In this way, you can avoid rereading the same pixels multiple times.

Choosing Block Size

The following three cases demonstrate the influence of block size on the performance of blockproc. In each of these cases, the total number of pixels in each block is approximately the same; only the size of the blocks is different.

15-13

15 Neighborhood and Block Operations

First, read in an image file and convert it to a TIFF.

imageA = imread('concordorthophoto.png','PNG'); imwrite(imageA,'concordorthophoto.tif','TIFF');

Use imfinfo to determine whether concordorthophoto.tif is organized in strips or tiles.

imfinfo concordorthophoto.tif

Select fields from the struct appear below:

Filename: 'concordorthophoto.tif'

FileSize: 6595038

Format: 'tif'

Width: 2956

Height: 2215

BitDepth: 8

ColorType: 'grayscale'

BitsPerSample: 8

StripOffsets: [1108x1 double]

SamplesPerPixel: 1

RowsPerStrip: 2

PlanarConfiguration: 'Chunky'

TileWidth: []

TileLength: []

The value 2 in RowsPerStrip indicates that this TIFF image is organized in strips with two rows per strip. Each strip spans the width of the image (2956 pixels) and is two pixels tall. The following three cases illustrate how choosing an appropriate block size can improve performance.

Case 1: Typical Case — Square Block. First try a square block of size

[500 500]. Each time the blockproc function accesses the disk it reads in an entire strip and discards any part of the strip not included in the

current block. With two rows per strip and 500 rows per block, the blockproc function accesses the disk 250 times for each block. The image is 2956 pixels wide and 500 rows wide, or approximately six blocks wide (2956/500 = 5.912). The blockproc function reads the same strip over and over again for each block that includes pixels contained in that strip. Since the image is six blocks wide, blockproc reads every strip of the file six times.

15-14

Соседние файлы в папке 2read