Sliding patches of an image
Show older comments
I have create a loop to crop an image to non overlapping patches.
Now i must change my code to create overlapping patches with step half of the x dimension of the patch
How can i do it?
[rows columns numberOfColorBands] = size(Image);
count=1;
for row=1:patch_row:rows %% patch_row and patch_col are the dimension of the patches
for col=1:patch_col:columns
patch{count}=Image_reshaped(row:row+patch_row-1,col:col+patch_col-1,:);
caption = sprintf('%s_%d.png',name,count);
count=count+1;
end
end
end
5 Comments
Rik
on 2 Oct 2020
The solution seems easy: divide the step size by two, but not the width. How would you implement that?
DIMITRIOS THEODOROPOULOS
on 2 Oct 2020
Rik
on 2 Oct 2020
Then you need to change your code.
If you want help, make it easy to be helped. Mention the entire error message. Make sure we can run your code.
For now my guesstimate is that you have an odd patch size and you forgot to round your indices.
DIMITRIOS THEODOROPOULOS
on 3 Oct 2020
Rik
on 3 Oct 2020
row=1:patch_row*0.5:rows;
row(end) %returns 1681
row(end)+patch_row-1 %returns 1712
Your last iteration will attempt to access a whole width, while there is only half a width left.
I would suggest you change your strategy and use indices as your loop variable, and then construct the row and column indices from those loop indices. That will also allow you to store patch properly.
Answers (0)
Categories
Find more on Computer Vision Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!