built the fuction from scratch

조회 수: 1 (최근 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