如何使用Matlab将图像裁剪为重叠的块?

问题描述 投票:0回答:1

我有一张图片,我想提取重叠的补丁。每个补丁的大小为16x16,重叠像素为10。我需要将每个提取的补丁保存为图像,并用数字重命名。我在Matlab中使用了以下代码。我需要重叠的像素为10,所以,我使用了stepsize = 10,这个stepsize的值是不是意味着重叠像素为10,或者我应该使用另一个值作为stepsize?我不确定该值是否可以正确执行此任务。有人可以帮我吗?

% Read input image.
rgbImage = imread('4.png');
figure;imshow(rgbImage);

[rows, columns, numColorChannels] = size(rgbImage);
stepSize = 10;
subImageWidth = 16;

 count=0;
% extract overlapping patches
for row = 1 : stepSize : rows
    row2 = min(row + subImageWidth - 1, rows);

    for col = 1 : stepSize : columns
         col2 = min(col + subImageWidth - 1, columns);
        subImage = rgbImage(row:row2, col:col2, :);

        baseFileName = sprintf('%d.jpg', count);
        Foldername='D:/input patches' ;
        fullFileName = fullfile(Foldername, baseFileName);
        imwrite(subImage, fullFileName);
        count=count+1;
    end
end
image matlab crop patch overlapping
1个回答
0
投票

stepSize = 10给出6个像素的重叠。例如,第二张图像从column=11开始,因此重叠的列为11到16。请尝试

stepSize = subImageWidth-overlap

overlap=10

其余代码看起来不错。

© www.soinside.com 2019 - 2024. All rights reserved.