Main Content

Parallel Block Processing on Large Image Files

If you have a Parallel Computing Toolbox™ license, then the blockproc function can take advantage of multiple processor cores on your machine to perform parallel block processing.

What is Parallel Block Processing?

Parallel block processing allows you to process many blocks simultaneously by distributing task computations to a collection of MATLAB® sessions, called workers. The MATLAB session with which you interact is called the client. The client reserves a collection of workers, called a parallel pool. Then, the client divides the input image into blocks and sends blocks to the worker MATLAB sessions. Each worker processes a subset of blocks and sends the results back to the client. The client aggregates the results into an output variable.

When to Use Parallel Block Processing

When processing small images, serial mode is expected to be faster than parallel mode. For larger images, however, you may see significant performance gains from parallel processing. The performance of parallel block processing depends on three factors:

  • Function used for processing

  • Image size

  • Block size

In general, using larger blocks while block processing an image results in faster performance than completing the same task using smaller blocks. However, sometimes the task or algorithm you are applying to your image requires a certain block size, and you must use smaller blocks. When block processing using smaller blocks, parallel block processing is typically faster than regular (serial) block processing, often by a large margin. If you are using larger blocks, however, you might need to experiment to determine whether parallel block processing saves computing time.

How to Use Parallel Block Processing

You must meet two conditions to use parallel block processing:

  • The source image is not specified as an ImageAdapter class.

  • A Parallel Computing Toolbox license exists in the MATLAB installation.

If you meet these conditions, then you can invoke parallel processing in blockproc by specifying the UseParallel name-value argument as true. When you do so, MATLAB automatically opens a parallel pool of workers on your local machine and uses all available workers to process the input image.

In the following example, compute a discrete cosine transform for each 8-by-8 block of an image in parallel:

blockFun = @(block_struct) dct2(block_struct.data);
result = blockproc(input_image,[8 8],blockFun, ...
   UseParallel=true);

Control parallel behavior with the parallel preferences, including scaling up to a cluster. See parpool (Parallel Computing Toolbox) for information on configuring your parallel environment.

See Also

Related Topics