This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Unpack binary image


BW = bwunpack(BWP,m)


BW = bwunpack(BWP,m) unpacks the packed binary image BWP. BWP is a uint32 array. When it unpacks BWP, bwunpack maps the least significant bit of the first row of BWP to the first pixel in the first row of BW. The most significant bit of the first element of BWP maps to the first pixel in the 32nd row of BW, and so on. BW is M-by-N, where N is the number of columns of BWP. If m is omitted, its default value is 32*size(BWP,1).

Binary image packing is used to accelerate some binary morphological operations, such as dilation and erosion. If the input to imdilate or imerode is a packed binary image, the functions use a specialized routine to perform the operation faster.

bwpack is used to create packed binary images.

Class Support

BWP is of class uint32 and must be real, 2-D, and nonsparse. The return value BW is of class uint8.


collapse all

Read binary image into the workspace.

BW = imread('text.png');

Pack the image.

BWp = bwpack(BW);

Dilate the packed image.

BWp_dilated = imdilate(BWp,ones(3,3),'ispacked');

Unpack the dilated image and display it.

BW_dilated = bwunpack(BWp_dilated, size(BW,1));


  • This function supports the generation of C code using MATLAB® Coder™. The code generated for this function uses a precompiled, platform-specific shared library. Use of a shared library preserves performance optimizations but limits the target platforms for which code can be generated. For more information, see Understand Code Generation with Image Processing Toolbox.

    When generating code, all input arguments must be compile-time constants.

Extended Capabilities

See Also

| |

Introduced before R2006a

Was this topic helpful?