| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Image Processing Toolbox |
| Contents | Index |
| Learn more about Image Processing Toolbox |
B = blockproc(A,[M N],fun)
B = blockproc(src_filename,[M N],fun)
blockproc(...,param,val,...)
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.
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
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:
|
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:
block_sruct.data: M-by-N or M-by-N-by-P matrix of block data
block_struct.border: a two-element vector, [V H], that specifies the size of the vertical and horizontal padding around the block of data
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');

colfilt | function_handle | nlfilter
![]() | blkproc | bwarea | ![]() |

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 |