zero padding on several images
Show older comments
Hello,
I have several images with several sizes (155x75x3,512x74x3...) and I want to do a zero-padding that all images have the same size in order to colvolute them with a 3x3 filter. I know padarray() but I dont know how to do that all images will have the same size at the end.
Any help would be great!
3 Comments
Turlough Hughes
on 7 May 2021
Edited: Turlough Hughes
on 7 May 2021
How do the images appear in your workspace? - 4D Matrix, loaded one at a time, cell array?
forgood2
on 8 May 2021
Image Analyst
on 8 May 2021
Well that's fine, but what about the answers below???
Accepted Answer
More Answers (2)
Image Analyst
on 8 May 2021
1 vote
Why not simply use imfilter() and not worry about resizing? There are several edge handling options with imfilter() -- more than with conv2().
if you want to use padarray, then use something like
currSize=size(currImg);
paddedImg=padarray(currImg,(aimSize-currSize)/2);
Watch out for differences in size that are not dividable by 2
1 Comment
DGM
on 8 May 2021
This is part of why I don't like dealing with padarray
currSize=size(currImg);
paddedImg=padarray(currImg,floor((aimSize-currSize)/2),0,'pre');
paddedImg=padarray(paddedImg,ceil((aimSize-currSize)/2),0,'post');
Most practical uses tend to require repeated calls for something so simple.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!