i have attached the file for clearity
built the fuction from scratch
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Sebastian Daneli
el 21 de Ag. de 2021
It’s hard to understand what you’re asking for. Perhaps you should as your teacher first and foremost
DGM
el 21 de Ag. de 2021
Editada: DGM
el 21 de Ag. de 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.
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!