-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathero-dil.cpp
More file actions
82 lines (79 loc) · 1.29 KB
/
ero-dil.cpp
File metadata and controls
82 lines (79 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
namedWindow("window1",WINDOW_NORMAL);
Mat a=imread("samps/erosion.png",0);
int f=1;
createTrackbar("threshold","window1",&f,10);
int f2=f-1;
Mat b=a.clone(),c;
while(1)
{
if(f2==f+234)
{/*
imshow("window1",c);
waitKey(1);
continue;*/
}
else
{
b=a.clone();
f2=f;
Mat img=a.clone();
c=img.clone();
while(f2--)
{
//erosion
img=c.clone();
for(int i=1;i<a.rows-1;i++)
{
for(int j=1;j<a.cols-1;j++)
{
if(a.at<uchar>(i,j)==255)
{
for(int k=-1;k<2;k++)
{
for(int l=-1;l<2;l++)
{
if(img.at<uchar>(i+k,j+l)==0)
{
b.at<uchar>(i,j)=0;
}
}
}
}
}
}
//dilation
c=b.clone();
for(int i=1;i<a.rows-1;i++)
{
for(int j=1;j<a.cols-1;j++)
{
if(b.at<uchar>(i,j)==0)
{
for(int k=-1;k<2;k++)
{
for(int l=-1;l<2;l++)
{
if(b.at<uchar>(i+k,j+l)==255)
{
c.at<uchar>(i,j)=255;
}
}
}
}
}
}
}
f2=f;
imshow("window1",b);
waitKey(1);
}
}
}