如何在matlab中将图像分割为64块

发布于 2024-10-20 18:33:48 字数 165 浏览 3 评论 0原文

我想计算每个图像的颜色布局描述符(CLD)。该算法包括四个阶段。在第一阶段,我必须将每个图像划分为 64 个块 i(8×8)n 以便从每个块计算单个代表颜色。我尝试使用(For 循环)将图像划分为 64 个块,但我得到 64婷图像。我想获得具有(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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红玫瑰 2024-10-27 18:33:48

将图像分区为块然后对其运行一些处理的一种方法是使用内置函数 BLOCKPROC(在旧版本的 Matlab 中称为 blkproc)。

%# 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 是您要应用于每个块的函数。您可以将其定义为代码的子函数、单独的 m 文件或匿名函数。输出将连接在 8x×8x 数组中,其中 x 是函数输出的大小。 myFunction 应该有一个输入参数 blockStruct,它是一个结构体,其字段 data 包含块的像素值,以及字段边框blockSizeimageSize位置

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.

寂寞美少年 2024-10-27 18:33:48

这里是我不久前为完全相同的问题(8x8 块、DCT 系数等)编写的一些代码...

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。通常在此应用程序中,您会使用一些重叠。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文