## i was writing a code for mathematical morphology dilation operation for a 1D signal but did not get proper output. Kindly help me with the proper code

### pavan sunder (view profile)

on 6 Oct 2016
Latest activity Answered by M E

### M E (view profile)

on 13 Jul 2019
the code i wrote:
function y_dil=dilation(x,se)
L=length(se)
x=[zeros(1,L) x];
N=length(x)
k=1+L;
y_dil=zeros(1,N);
for n=k:N
for i=1:L
r(i)=max(x(n-i)+se(i))
end
Y_dil(k-L)=max(r);
k=k+1;
end
end

### Massimo Zanetti (view profile)

on 6 Oct 2016

Use imdilate function which is already in Matlab. https://it.mathworks.com/help/images/ref/imdilate.html
For example, if your signal is SIGNAL matrix (1xN matrix), and your structuring element is SE=[1,1,1], try this:
DIL_SIGNAL = imdilate(SIGNAL,SE)

Show 1 older comment
Massimo Zanetti

### Massimo Zanetti (view profile)

on 8 Oct 2016
Mmm, it should work. See my outputs:
S=[1,1,1,0,0,0,0,1,1,1,0,0];
DIL = imdilate(S,[1,1,1]);
%then I get (as expected)
%DIL=[1,1,1,1,0,0,1,1,1,1,1,0]
Try this on your machine and tell if works.
Walter Roberson

### Walter Roberson (view profile)

on 8 Oct 2016
A 1D signal is a very thin 2D signal ;-)
Massimo Zanetti

on 8 Oct 2016
Hahahaha, true.