-
Notifications
You must be signed in to change notification settings - Fork 0
/
erosion.c
66 lines (65 loc) · 1.53 KB
/
erosion.c
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
#include<stdio.h>
#include<stdlib.h>
#include "image.h"
#define SE_VAL 5
void imerode(GrayImage *originalImage,GrayImage *finalImage,int SE[SE_VAL][SE_VAL])
{
int i,j,k,l;
int temp[SE_VAL][SE_VAL];
finalImage->row=originalImage->row;
finalImage->col=originalImage->col;
finalImage->maxval=originalImage->maxval;
finalImage->f=(int **)malloc(sizeof(int *)*originalImage->row);
for(i=0;i<originalImage->row;i++)
finalImage->f[i]=(int *)malloc(sizeof(int)*originalImage->col);
for(i=0;i<originalImage->row;i++)
{
for(j=0;j<originalImage->col;j++)
{
for(s=0;s<SE_VAL;s++)
{
for(t=0;t<SE_VAL;t++)
{
temp[s][t]=originalImage->f[i+s][j+t];
}
}
for(i=0;i<SE_VAL;i++)
{
for(j=0;j<SE_VAL;j++)
{
finalImage->f[i][j]=(temp>finalImage->f[i][j])?finalImage->f[i][j]:temp;
}
}
}
}
}
void imdilate(GrayImage *originalImage,GrayImage *finalImage,int SE[SE_VAL][SE_VAL])
{
int i,j,k,l;
int temp[SE_VAL][SE_VAL];
finalImage->row=originalImage->row;
finalImage->col=originalImage->col;
finalImage->f=(int **)malloc(sizeof(int *)*originalImage->row);
for(i=0;i<originalImage->row;i++)
finalImage->f[i]=(int *)malloc(sizeof(int)*originalImage->col);
for(i=0;i<originalImage->row;i++)
{
for(j=0;j<originalImage->col;j++)
{
for(s=0;s<SE_VAL;s++)
{
for(t=0;t<SE_VAL;t++)
{
temp[s][t]=originalImage->f[i-s][j-t];
}
}
for(i=0;i<SE_VAL;i++)
{
for(j=0;j<SE_VAL;j++)
{
finalImage->f[i][j]=(temp<finalImage->f[i][j])?finalImage->f[i][j]:temp;
}
}
}
}
}