我有一张图片,我想提取重叠的补丁。每个补丁的大小为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
stepSize = 10
给出6个像素的重叠。例如,第二张图像从column=11
开始,因此重叠的列为11到16。请尝试
stepSize = subImageWidth-overlap
与
overlap=10
其余代码看起来不错。