如何在matlab中将图像分割为64块
我想为每个图像计算颜色布局描述符(CLD)。该算法包括四个阶段。在第一阶段我必须将每个图像分成64块i(8×8)n以便从每个块计算单个代表性颜色..我尝试使用(For循环)将图像分割成64块但我得到64 ting图像。我希望得到带有(8×8)块的图像,以便通过应用DCT变换然后Zigzag扫描来完成算法
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
这里我写了几段完全相同的问题代码(8x8块,DCT系数等)......
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
设置一个块和下一个块之间的偏移量。在这种情况下,它每次偏移一个像素。但是,如果你想要非重叠的块,你应该将它设置为8.通常在这个应用程序中,你使用一些重叠。
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.