built the fuction from scratch

5 views (last 30 days)
Muhammad on 21 Aug 2021
Edited: DGM on 21 Aug 2021
a = input('Please input the matrix like "[1, 2; 3, 4]":');
% mf= ones(3,3)
% meanA = mean(A(:))
a1= padarray(a,[1 1],1)
[m n]=size(a1);
for i=2:(m-1)
for j =2:(n-1)
vrow= v(:)'
r= sum(v(:))/9;
i made the mean filter that takes the matrix input and perform mean
but my teacher asked me to make this filter from scratch .how i can it
DGM on 21 Aug 2021
Edited: DGM on 21 Aug 2021
What exactly is the problem you're having? It seems like what you have is mostly there. There are a few points:
Don't use input() for collecting data. This is unnecessarily tedious and error-prone. Data can be defined in an external image or mat file, or for small test arrays in an ad-hoc script, it can just be a simple literal or even generated programmatically. There's no reason to force the user to type it in manually every single time.
I'm not sure why you're taking ceil() on the output. Nothing here implies that the input or output are strictly integer-valued. If integer output is required, scale/cast the data to an integer class so that it's compatible with what imwrite() or imread() might expect.
vrow isn't used for anything
The routine is only capable of a 3x3 rectangular filter. That may satisfy the requirements, but would be limiting for a practical filter. Whether or not that matters is up to you and what those requirements are.
Lastly, this isn't yet a function. It's still just a script. If it's required to implement this as a function, you'll have to do that.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!