Products & Services Solutions Academia Support User Community Company

Learn more about Image Processing Toolbox   

blockproc - Distinct block processing for image

Syntax

B = blockproc(A,[M N],fun)
B = blockproc(src_filename,[M N],fun)
blockproc(...,param,val,...)

Description

B = blockproc(A,[M N],fun) processes the image A by applying the function fun to each distinct M-by-N block of A and concatenating the results into B, the output matrix. fun is a function handle to a function that accepts a block struct as input and returns a matrix, vector, or scalar Y. For example, Y = fun(block_struct). (For more information about a block struct, see the Definition section below.) For each block of data in the input image, A, blockproc passes the block in a block struct to the user function, fun, to produce Y, the corresponding block in the output image. If Y is empty, blockproc does not generate any output and returns empty after processing all blocks. Choosing an appropriate block size can significantly improve performance. For more information, see Block Size and Performance in the Image Processing Toolbox documentation.

B = blockproc(src_filename,[M N],fun)processes the image src_filename, reading and processing one block at a time. This syntax is useful for processing very large images since only one block of the image is read into memory at a time. If the output matrix B is too large to fit into memory, use the 'Destination' parameter/value pair to write the output to a file.

blockproc(...,param,val,...) processes the input image, specifying parameters and corresponding values that control various aspects of the block behavior. Parameter names are not case sensitive.

Inputs

A

Input image

[M N]

Block size of A

fun

Function handle to a function that accepts a block struct as input and returns a matrix, vector, or scalar

src_filename

Input image

param,val

Parameters and values that control block behavior

ParameterDescription
'Destination'

A string file name designating the output location for blockproc. This parameter directs blockproc to write its output to the specified file. Use this parameter if you expect your function output to be too large to fit practically into memory. If the specified file exists, it is overwritten. The 'Destination' parameter provides a workflow for file-to-file image processing for arbitrarily large images. If you specify the 'Destination' parameter, blockproc does not return a value.

'BorderSize'

A two-element vector, [V H], specifying the amount of border pixels to add to each block. The function adds V rows above and below each block and H columns left and right of each block. The size of each resulting block will be:

[M + 2*V, N + 2*H]

The default is [0 0], meaning no border. By default, the function automatically removes the border from the result of fun. See the 'TrimBorder' parameter for more information. The function pads blocks with borders extending beyond the image edges with zeros.

'TrimBorder'

A logical scalar. When set to true, the blockproc function trims off border pixels from the output of the user function, fun. The function removes V rows from the top and bottom of the output of fun, and H columns from the left and right edges. The 'BorderSize' parameter defines V and H. The default is true, meaning that the blockproc function automatically removes borders from the fun output.

'PadPartialBlocks'

A logical scalar. When set to true, blockproc pads partial blocks to make them full-sized (M-by-N) blocks. Partial blocks arise when the image size is not exactly divisible by the block size. If they exist, partial blocks lie along the right and bottom edge of the image. The default is false, meaning that the function does not pad the partial blocks, but processes them as-is. blockproc uses zeros to pad partial blocks when necessary.

File Format Support: Input and output files for blockproc (as specified by src_filename and the 'Destination' parameter) must have one of the following file types and must be named with one of the listed file extensions:

  • Read/Write File Formats: TIFF (*.tif, *.tiff)

  • Read-Only File Formats: JPEG2000 (*.jp2, *.jpf, *.jpx, *.j2c, *.j2k) (Solaris™ 64-bit platform does not support JPEG2000 file formats.)

Definition

A block struct is a MATLAB structure that contains the block data as well as other information about the block. Fields in the block struct are:

Examples

Generate an image thumbnail:

fun = @(block_struct) imresize(block_struct.data,0.15);
I = imread('pears.png');
I2 = blockproc(I,[100 100],fun);
figure;
imshow(I);
figure;
imshow(I2);

 

Set the pixels in each 32-by-32 block to the standard deviation of the elements in that block:

fun = @(block_struct) ...
   std2(block_struct.data) * ones(size(block_struct.data));
I2 = blockproc('moon.tif',[32 32],fun);
figure;
imshow('moon.tif');
figure;
imshow(I2,[]);

 

Switch the red and green bands of an RGB image and write the results to a new TIFF file:

I = imread('peppers.png');
fun = @(block_struct) block_struct.data(:,:,[2 1 3]);
blockproc(I,[200 200],fun,'Destination','grb_peppers.tif');
figure;
imshow('peppers.png');
figure;
imshow('grb_peppers.tif');

See Also

colfilt | function_handle | nlfilter

How To

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS