将图像分为不重叠和重叠的块

发布于 2024-12-20 06:23:26 字数 185 浏览 3 评论 0原文

我有一张 256*256 的图像。我必须根据下面给定的重叠规则将图像分成大小为 W * W 的子块,其中 W=3,4,.....27:
如果 W<8 则没有块重叠 if 8<=W<=13 则块重叠 50% 如果 W>13 则块重叠 75% 如何在matlab中实现它,特别是第二条和第三条规则

I have an image of 256*256.I have to divide the image into sub blocks of size W * W,where W=3,4,.....27 according to the given overlapping rules below:
if W<8 thn no overlapping of blocks
if 8<=W<=13 thn 50% overlapping of blocks
if W>13 thn 75% overlapping of blocks
how to implement it in matlab,particularly in 2nd and in 3rd rule

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

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

发布评论

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

评论(1

一世旳自豪 2024-12-27 06:23:26

实现您感兴趣的目标的最快、最简单的方法如下:

function blocks = DivideImage(im, W)

if W <= 7
    step = W;
elseif W <= 13
    step = round(0.25 * W);
else
    step = round(0.125 * W);
end

startPos = 0:step:size(im,1)-W;

blocks = cell(numel(startPos), numel(startPos));
for i = 1:numel(startPos)
    for j = 1:numel(startPos)
        blocks{i,j} = im(startPos(i)+(1:W), startPos(j)+(1:W));
    end
end

请注意,当 W 没有完全除以 size(im,1) 时,则它会从右边缘和下边缘丢弃一些点,因此您需要再次查看它如何设置 startPos 的值。

The quickest and simplest way of achieving something like what you're interested in is as follows:

function blocks = DivideImage(im, W)

if W <= 7
    step = W;
elseif W <= 13
    step = round(0.25 * W);
else
    step = round(0.125 * W);
end

startPos = 0:step:size(im,1)-W;

blocks = cell(numel(startPos), numel(startPos));
for i = 1:numel(startPos)
    for j = 1:numel(startPos)
        blocks{i,j} = im(startPos(i)+(1:W), startPos(j)+(1:W));
    end
end

Note that when W doesn't divide exactly into size(im,1) then it will drop some of the points from the right and bottom edges, so you will want to look again at how it's setting the values of startPos.

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