-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvision.h
116 lines (98 loc) · 3.35 KB
/
cvision.h
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @author Eduardo Oliveira;
* @copyright INSTITUTO POLITÉCNICO DO CÁVADO E DO AVE - 2019/2020 - ENGENHARIA DE SISTEMAS INFORMÁTICOS - VISÃO POR COMPUTADOR
* @email [email protected];
* @create date 13-02-2020 12:00:36
* @modify date 21-04-2020 12:36:00
* @desc Minimal Image Library for Computer Vision - Sobel and Prewitt edge methods example for Netpbm images
* @version 0.1.2
*/
#define VC_DEBUG
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define MINWIDTH 0
#define MINHEIGHT 0
#define VC_CH_1 1
#define VC_CH_2 2
#define VC_CH_3 3
#define GRAYLEVELS 256
#define SIZEOFUCHAR 255
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// IMAGE STRUCTURE
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
typedef struct
{
unsigned char *data;
int width, height;
int channels; // Binary/Gray = 1; RGB = 3
int levels; // Binary = 1; Gray [1,255]; RGB [1,255]
int bytesperline; // width * channels
} IVC;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// EDGE DETECTION
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* @summary: Sobel edge detection
* @src: Receives the source image pointer
* @dst: Receives the destination image pointer
* @th: receives the edging threshold [0.001, 1.00]
* @return: true if the operation succeeds, false if not
*/
int vc_gray_edge_sobel(IVC *src, IVC *dst, float th);
/**
* @summary: Prewitt edge detection
* @src: Receives the source image pointer
* @dst: Receives the destination image pointer
* @th: receives the edging threshold
* @return: true if the operation succeeds, false if not
*/
int vc_gray_edge_prewitt(IVC *src, IVC *dst, float th);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Image Convertion
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* @summary: Converts a rgb image to gray scale
* @src: Receives the source image pointer
* @dst: Receives the destination image pointer
* @return true if the operation succeeds, false if not
*/
int vc_rgb_to_gray(IVC *src, IVC *dst);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Image Memory Alloc & Free
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* @summary: Memory alloc for a image by parameters
* @width: Receives the image width
* @height: Receives the image height
* @channels: Receives the number of image channels
* @levels: Receives the image levels
* @return pointer to the image structure
*/
IVC *vc_image_new(int width, int height, int channels, int levels);
/**
* @summary: Image memory free
* @image: Receives the image pointer
* @return NULL if the image pointer was set free
*/
IVC *vc_image_free(IVC *image);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Image Read and Write (PBM, PGM E PPM)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* @summary: Read Image
* @filename: Receives the file name and extension
* @return Pointer to the struct or NULL
*/
IVC *vc_read_image(char *filename);
/**
* @summary: Save Image
* @filename: Receives the file name and extension
* @image: Receives the pointer to the image in memory
* @return True if success, or false if not
*/
int vc_write_image(char *filename, IVC *image);