Skip to content

Instantly share code, notes, and snippets.

@nelsondspy
Created September 11, 2014 04:13
Show Gist options
  • Save nelsondspy/7fc561d58b464fc3bc05 to your computer and use it in GitHub Desktop.
Save nelsondspy/7fc561d58b464fc3bc05 to your computer and use it in GitHub Desktop.
pseudomediana de 5 elementos - sin optimizar (necesita mejor tratamiento de bordes )
function imgresult = pseudo_mediana( img )
%pseudo_mediana filtro pseudo mediana
%Autor Nelson Duranhona 20140911 YYYYMMDD
[ M ,N ] = size(img);
imgresult = uint8(zeros(M,N));
M = M-1;
N = N-1;
D_VERT = 1;
D_HOR = 1 ;
INIF = 1 + D_VERT;
INIC= 1 + D_HOR;
%test
cont= 0 ;NOcont=0;
for i=1:M
for j=1:N
%obtiene la vecindad
ve = imvencidad( img, [i , j], 1 , 1 );
if size(ve , 2) < 3 || size(ve , 1) < 3
imgresult(i, j) = img(i, j);
cont = cont + 1;
continue;
end
NOcont = NOcont + 1 ;
ve(1,1)=0 ; ve(3,3)=0 ; ve(3,1)=0; ve(1,3)=0;
% reduce a una dimension y ordena los valores
ve_ord = sort(reshape( ve , 1, []) );
ve_ord = ve_ord( 5:9 ); %omite los 4 primeros elementos ( 0's)
a=ve_ord(1);b=ve_ord(2);c=ve_ord(3); d=ve_ord(4);e = ve_ord(5);
psmed = (1/2 * max( [min([a,b,c]), min([b,c,d]), min([c,d,e]) ])) + ...
(1/2 * min([max([a,b,c]),max([b,c,d]),max([c,d,e] )]));
imgresult(i, j) = psmed ;
end
end
disp('NOcont');disp(NOcont);disp('cont');disp(cont);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment