%Función que segmenta mediante crecimiento de regiones por semilla %utilizando como semilla inicial la función impixel y con rango de %intensidades válido de 0.02 name=input('introduzca nombre de la imagen: ','s'); y=dicomread(name); minimo=min(min(y)); resul=y-minimo; maximo=max(max(resul)); maximo=double(maximo); I=double(resul)/maximo; imhist(I); I2=imadjust(I,[0.4;1],[0;1]); clf imshow(I2,[]),title('Seleccione semilla') %Implantamos semilla title('seleccione semilla'),[col,fil,sem]=impixel(I2) sem=I2(fil,col) umbral=0.02; interior=zeros(512,512); %inicializamos matriz interior(0=no visitado,1=visitado y pertenece,2=visitado y no pertenece) I3=zeros(512,512); y=fil; x=col; for i2=1:512 %recorremos filas for j2=1:512 %recorremos columnas if (interior(i2,j2)==0 || interior(i2,j2)==2) if(abs(sem-I2(i2,j2))>umbral) interior(i2,j2)=2; else interior(i2,j2)=1; indfila=i2; indcolu=j2; I3(indfila,indcolu)=I2(indfila,indcolu); queue(1,1)=i2; queue(1,2)=j2; p=1; q=1; while(q<=p) i=queue(q,1); j=queue(q,2); q=q+1; if((i+1)<512) if (interior(i+1,j)==0 || interior(i+1,j)==2) if(abs(I2(i2,j2)-I2(i+1,j))>umbral) interior(i+1,j)=2; else interior(i+1,j)=1; indfila=i+1; indcolu=j; I3(indfila,indcolu)=I2(indfila,indcolu); p=p+1; queue(p,1)=i+1; queue(p,2)=j; end end end if((i-1)>0) if(interior(i-1,j)==0 || interior(i-1,j)==2) if(abs(I2(i2,j2)-I2(i-1,j))>umbral) interior(i-1,j)=2; else interior(i-1,j)=1; indfila=i-1; indcolu=j; I3(indfila,indcolu)=I2(indfila,indcolu); p=p+1; queue(p,1)=i-1; queue(p,2)=j; end end end if ((j+1)<512) if(interior(i,j+1)==0 || interior(i,j+1)==2) if(abs(I2(i2,j2)-I2(i,j+1))>umbral) interior(i,j+1)=2; else interior(i,j+1)=1; indfila=i; indcolu=j+1; I3(indfila,indcolu)=I2(indfila,indcolu); p=p+1; queue(p,1)=i; queue(p,2)=j+1; end end end if((j-1)>0) if(interior(i,j-1)==0 || interior(i,j-1)==2) if(abs(I2(i2,j2)-I2(i,j-1))>umbral) interior(i,j-1)=2; else interior(i,j-1)=1; indfila=i; indcolu=j-1; I3(indfila,indcolu)=I2(indfila,indcolu); p=p+1; queue(p,1)=i; queue(p,2)=j-1; end end end end end end end end imview(I3) I4=medfilt2(I3); I5=medfilt2(I4); imview(I5)