Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d3ceea

Browse files
Morphology
Dilation & Erosion.
1 parent c4717db commit 2d3ceea

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

‎Morphology/dil.jpg‎

33.5 KB
Loading[フレーム]

‎Morphology/dil.m‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%Dilation
2+
3+
A=imread('text.png');
4+
A=im2bw(A);
5+
%Structuring element
6+
B2=getnhood(strel('line',7,90));
7+
m=floor(size(B2,1)/2);
8+
n=floor(size(B2,2)/2);
9+
%Pad array on all the sides
10+
C=padarray(A,[m n]);
11+
D=false(size(A));
12+
for i=1:size(C,1)-(2*m)
13+
for j=1:size(C,2)-(2*n)
14+
Temp=C(i:i+(2*m),j:j+(2*n));
15+
D(i,j)=max(max(Temp&B2));
16+
end
17+
end
18+
subplot(2,1,1),
19+
imshow(A), title('Original')
20+
subplot(2,1,2),
21+
imshow(D), title('Dilated')

‎Morphology/dilero.jpg‎

24.9 KB
Loading[フレーム]

‎Morphology/dilero.m‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
%Dilation Erosion
2+
A=eye(50);
3+
Acom= magic(50);
4+
for i=1:50
5+
for j=1:50
6+
Acom(i,j)=rem(Acom(i,j),2);
7+
end
8+
end
9+
%Structuring element
10+
B=[1 0 1; 0 0 1; 1 1 0];
11+
%Pad zeros on all the sides
12+
C=padarray(A,[1 1]);
13+
%Intialize a matrix of matrix size A with zeros
14+
D=false(size(A));
15+
for i=1:size(C,1)-2
16+
for j=1:size(C,2)-2
17+
%Perform logical AND operation
18+
D(i,j)=sum(sum(B&C(i:i+2,j:j+2)));
19+
end
20+
end
21+
%Structuring element
22+
B1=[1 1 0];
23+
%Pad array with ones on both sides
24+
E=padarray(Acom,[0 1],1);
25+
%Intialize the matrix D of size A with zeros
26+
F=false(size(Acom));
27+
for i=1:size(E,1)
28+
for j=1:size(E,2)-2
29+
In=E(i,j:j+2);
30+
%Find the position of ones in the structuring element
31+
In1=find(B1==1);
32+
%Check whether the elements in the window have the value one in the
33+
%same positions of the structuring element
34+
if(In(In1)==1)
35+
F(i,j)=1;
36+
end
37+
end
38+
end
39+
subplot(2,2,1),
40+
imshow(A), title('Original Dilated');
41+
subplot(2,2,2),
42+
imshow(D), title('Dilated');
43+
subplot(2,2,3),
44+
imshow(Acom), title('Original Eroded');
45+
subplot(2,2,4),
46+
imshow(F), title('Eroded');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /