Segment the image into blocks

前端 未结 1 1626
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 05:50

Let us consider an image Y of size 512x512.

The code below serves to segment the image Y into blocks where each block take the size 8x8.

Matlab Code:         


        
相关标签:
1条回答
  • 2020-12-07 06:12

    Try using mat2cell to break the image up into blocks:

    bsX = 10; bsY = 10;
    [m,n] = size(Y);
    numFullBlocksX = floor(n/bsX); numFullBlocksY = floor(m/bsY);
    xBlocks = [repmat(bsX,numFullBlocksX,1); mod(n,bsX)*ones(mod(n,bsX)>0)];
    yBlocks = [repmat(bsY,numFullBlocksY,1); mod(m,bsY)*ones(mod(m,bsY)>0)];
    blockCell = mat2cell(Y,yBlocks,xBlocks)
    

    To instead go from number of blocks to block size, lead with these two lines instead of bsX = 10; bsY = 10;:

    numBlocksX = 10; numBlocksY = 10;
    bsX = ceil(n/numBlocksX); bsY = ceil(m/numBlocksY);
    
    0 讨论(0)
提交回复
热议问题