built the fuction from scratch

2 次查看(过去 30 天)
Muhammad
Muhammad 2021-8-21
编辑: DGM 2021-8-21
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);
c=zeros(size(a));
for i=2:(m-1)
for j =2:(n-1)
v=a1(i-1:i+1,j-1:j+1)
vrow= v(:)'
r= sum(v(:))/9;
c(i-1,j-1)=ceil(r)
end
end
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
  4 个评论
Sebastian Daneli
Sebastian Daneli 2021-8-21
It’s hard to understand what you’re asking for. Perhaps you should as your teacher first and foremost
DGM
DGM 2021-8-21
编辑:DGM 2021-8-21
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by