How to partition an image to 64 block in matlab

zenab picture zenab · Mar 6, 2011 · Viewed 8.7k times · Source

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

Answer

Jonas picture Jonas · Mar 6, 2011

One way to partition your image into blocks and then run some processing on it is to use the built-in function BLOCKPROC (called blkproc in older versions of Matlab).

%# find block length in order to get 64 blocks
imageSize = size(img);
blockLen = round(imageSize(1:2)/8);

%# apply a function to each block
out = blocproc(img,blockLen,@myFunction)

myFunction is the function that you'd like to apply to each block. You can define it as a subfunction of your code, or a separate m-file, or an anonymous function. The output will be catenated in an 8x-by-8x array, where x is the size of the output of your function. myFunction should expect a single input argument, blockStruct, which is a structure with fields data containing the pixel values of the block, as well as fields border, blockSize, imageSize, and location.