# bestblk

Determine optimal block size for block processing

## Syntax

``siz = bestblk([M N],k)``
``[m,n] = bestblk([M N],k)``

## Description

example

````siz = bestblk([M N],k)` returns the optimal block size for block processing of an `M`-by-`N` image. The optimal block size minimizes the padding required along the outer partial blocks. `k` specifies the maximum row and column dimensions for the block.```
````[m,n] = bestblk([M N],k)` returns the row and column dimensions for the block in `m` and `n`, respectively.```

## Examples

collapse all

`siz = bestblk([640 800],72)`
```siz = 1×2 64 50 ```

## Input Arguments

collapse all

Image size, specified as a 2-element vector of positive integers. `M` is the number of rows and `N` is the number of columns in the image.

Data Types: `double`

Maximum number of block rows or columns, specified as a positive integer.

Data Types: `double`

## Output Arguments

collapse all

Optimal block size, returned as a 2-element numeric row vector. `siz` is equivalent to [`m` `n`].

Optimal number of block rows or columns, returned as a numeric scalar.

## Algorithms

The algorithm for determining the optimal value of `m` from `M` and `k` is:

• If `M` is less than or equal to `k`, return `M`.

• If `M` is greater than `k`, consider all values between `min(M/10,k/2)` and `k`. Return the value that minimizes the padding required.

The same algorithm is used to find the optimal value of `n` from `N` and `k`.