Search code examples
imagematlabimage-processingblock

Divide an image into equal sized blocks using MATLAB and use Gabor filter


How to divide a facial image of size 120x120 into 64 blocks of 15x15 pixel size using MATLAB? Then I want to convolve each 15x15 block with Gabor filter. I failed in using the blkproc function.How can I do this?


Solution

  • To extract these blocks you can use the following, assuming img is a 120x120 image matrix, c=15, w=8:

    blocks = reshape(permute(reshape(img, c, w, c, w), [1 3 2 4]), c, c, w * w)
    

    Now blocks is a 15x15x64 matrix, and blocks(:, :, i) is a 15x15 matrix representing the i-th block.