View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 1 rating Rate this file 14 Downloads (last 30 days) File Size: 2.88 KB File ID: #40173 Version: 1.2
image thumbnail



Jurgen (view profile)


04 Feb 2013 (Updated )

Split image or matrix into subparts using simple syntax.

| Watch this File

File Information

Divide image/matrix into cell array of blocks. Can specify per dimension in how many pieces it needs to divide. See examples in help section for a quick idea of how it works.

I = imsplit(im,2) splits image into 2x2 blocks etc.

I = imsplit(rgb,3,3) splits an rgb image 'rgb' into 1x1x3 cell array containing colorplanes.

Instead of a mat2cell wrapper this uses my own implementation of indexing (using permute) to split matrices into smaller and smaller pieces.
Since MATLAB's Answers get a lot of those submatrix questions I thought I'd share what I made.

No handling of uneven divisions, ie can not divide 400 pixel width into 3 blocks--common usage with images is crop or resize, then split. Recommend mat2cell or Matt J's mat2tiles(File ID: #35085) for uneven blocks.

May be faster if use a wrapper for mat2cell, but still pretty fast in its own right.

If you have imdisp() you can display the resulting cell array as you would an image. The illustration was created using imdisp with the 'bordersize' option to add 1% margins between the blocks.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
09 May 2013 Khalid

Khalid (view profile)

21 Apr 2013 Jurgen

Jurgen (view profile)

Thanks. I use linear indexing (lines93-95). Will fix if I have time. For now add at the end of the main function (outside for loop) "BLKS = permute(reshape(BLKS,fliplr(N)),fliplr(DIMS));"

Comment only
21 Apr 2013 Jurgen

Jurgen (view profile)

Sorry I meant:
"BLKS = permute(reshape(BLKS,fliplr(N)),fliplr(DIMS));"

Comment only
11 Apr 2013 Suraj Kamya

Suraj Kamya (view profile)

Your code is working good but after dividing an image in to blocks it does not combine back as original.. one, even if you use cell2mat..

Comment only
06 Feb 2013 1.1

Expanded description

02 May 2013 1.2

Patched cell indexing. Cell2mat() should return original for all outputs now.

Contact us