Search code examples
imagematlabdata-partitioning

How to partition an image to 64 block in matlab


I want to compute the Color Layout Descriptor (CLD) for each image.. this algorithm include four stages . in the First stage I must Partition each image into 64 block i(8×8)n order to compute a single representative color from each block .. I try to partition the image into 64 block by using (For loop) but I get 64 ting image. I want to get image with (8×8) block in order to complete the algorithm by apply the DCT transformation then Zigzag scanning


Solution

  • Here some pieces of code that I wrote for the exact same problem (8x8 blocks, DCT coefficients, etc) sometime ago...

    img=imread('filename')
    [img_x,img_y]=size(img);
    
    block_size=8;
    slide_len=1;
    
    for ix=block_size/2:slide_len:img_x-block_size/2
        for jy=block_size/2:slide_len:img_y-block_size/2
            current_block=img((ix-block_size/2+1):(ix+block_size/2),(jy-block_size/2+1):(jy+block_size/2));
            dct_coeff=reshape(dct2(current_block),1,block_size^2);
    
            <insert any other code you want to run here>
        end
    end
    

    slide_len sets the offset between one block and the next. In this case it offsets by one pixel each time. however, if you want non-overlapping blocks, you should set it to 8. usually in this application, you use some overlaps.