-
Notifications
You must be signed in to change notification settings - Fork 0
/
morphprocessing.c
71 lines (59 loc) · 1.73 KB
/
morphprocessing.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
67
68
69
70
71
#include <stdlib.h>
#include <string.h>
#include "structs.h"
extern FILE *Fp_log, *Fp_log_median; // log file
extern int area;
dilation(unsigned char **image_pixel,int height,int width)
{
int i,j;
unsigned char **tmppixel;
tmppixel=(unsigned char**)mymalloc2(height,width,sizeof(unsigned char));
for(j=0;j<height;j++)
for(i=0;i<width;i++)
tmppixel[j][i]=image_pixel[j][i];
for(j=1;j<height-1;j++)
for(i=1;i<width-1;i++){
if(tmppixel[j-1][i-1]==LOW ||
tmppixel[j-1][i ]==LOW ||
tmppixel[j-1][i+1]==LOW ||
tmppixel[j ][i-1]==LOW ||
tmppixel[j ][i+1]==LOW ||
tmppixel[j+1][i-1]==LOW ||
tmppixel[j+1][i ]==LOW ||
tmppixel[j+1][i+1]==LOW )
image_pixel[j][i]=LOW;
}
myfree2((void **)tmppixel,height);
}
erosion(unsigned char **image_pixel,int height,int width)
{
int i,j;
unsigned char **tmppixel;
tmppixel=(unsigned char**)mymalloc2(height,width,sizeof(unsigned char));
for(j=0;j<height;j++)
for(i=0;i<width;i++)
tmppixel[j][i]=image_pixel[j][i];
for(j=1;j<height-1;j++)
for(i=1;i<width-1;i++){
if(tmppixel[j-1][i-1]==HIGH ||
tmppixel[j-1][i ]==HIGH ||
tmppixel[j-1][i+1]==HIGH ||
tmppixel[j ][i-1]==HIGH ||
tmppixel[j ][i+1]==HIGH ||
tmppixel[j+1][i-1]==HIGH ||
tmppixel[j+1][i ]==HIGH ||
tmppixel[j+1][i+1]==HIGH )
image_pixel[j][i]=HIGH;
}
myfree2((void **)tmppixel,height);
}
opening(unsigned char **image_pixel,int height,int width)
{
erosion(image_pixel,height,width);
dilation(image_pixel,height,width);
}
closing(unsigned char **image_pixel,int height,int width)
{
dilation(image_pixel,height,width);
erosion(image_pixel,height,width);
}