How can i use zero-padding in an image?

134 views (last 30 days)
Hello ,
I have an image(512x512) and i want to do zero-padding in order to covolute it with a filter .
The problem here is that i dont know how to do that ,meaning that i dont know where the zeros should be (around the image or next to it) and furthermore the size of the zero-padding.
Any help would be valuable.

Accepted Answer

Image Analyst
Image Analyst on 13 Oct 2020
There is a built-in function for that. It's called padarray().

Sign in to comment.

More Answers (1)

Ameer Hamza
Ameer Hamza on 13 Oct 2020
Edited: Ameer Hamza on 13 Oct 2020
You don't need to do padding yourself. imfilter(): automatically does it based on the option you pass
filtered_image = imfilter(img, fil, 'same')
If you want to understand the concept behind it, then this link might be helpful:
  1 Comment
Gn Gnk
Gn Gnk on 13 Oct 2020
Thank you for your quick response . I am familiar with imfilter() but i actually want to do this process by myself , thats why i am really confused.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!