-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDAISGram.h
323 lines (286 loc) · 8.77 KB
/
DAISGram.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#ifndef DAISGRAM_H
#define DAISGRAM_H
#include <iostream>
#include <string>
#include "dais_exc.h"
#include "libbmp.h"
#include "tensor.h"
using namespace std;
class DAISGram {
private:
Tensor data;
public:
//DAISGram();
//~DAISGram();
/**
* Load a bitmap from file
*
* @param filename String containing the path of the file
*/
void load_image(string filename);
/**
* Save a DAISGram object to a bitmap file.
*
* Data is clamped to 0,255 before saving it.
*
* @param filename String containing the path where to store the image.
*/
void save_image(string filename);
/**
* Get rows
*
* @return returns the number of rows in the image
*/
int getRows() const;
/**
* Get columns
*
* @return returns the number of columns in the image
*/
int getCols() const;
/**
* Get depth
*
* @return returns the number of channels in the image
*/
int getDepth() const;
/**
* Brighten the image
*
* It sums the bright variable to all the values in the image.
*
* Before returning the image, the corresponding tensor should be clamped in [0,255]
*
* @param bright the amount of bright to add (if negative the image gets darker)
* @return returns a new DAISGram containing the modified object
*/
DAISGram brighten(float bright) const;
/**
* Create a grayscale version of the object
*
* A grayscale image is produced by substituting each pixel with its average on all the channel
*
* @return returns a new DAISGram containing the modified object
*/
DAISGram grayscale() const;
/**
* Create a Warhol effect on the image
*
* This function returns a composition of 4 different images in which the:
* - top left is the original image
* - top right is the original image in which the Red and Green channel are swapped
* - bottom left is the original image in which the Blue and Green channel are swapped
* - bottom right is the original image in which the Red and Blue channel are swapped
*
* The output image is twice the dimensions of the original one.
*
* @return returns a new DAISGram containing the modified object
*/
DAISGram warhol() const;
/**
* Sharpen the image
*
* This function makes the image sharper by convolving it with a sharp filter
*
* filter[3][3]
* 0 -1 0
* -1 5 -1
* 0 -1 0
*
* Before returning the image, the corresponding tensor should be clamped in [0,255]
*
* @return returns a new DAISGram containing the modified object
*/
DAISGram sharpen() const;
/**
* Emboss the image
*
* This function makes the image embossed (a light 3D effect) by convolving it with an
* embossing filter
*
* filter[3][3]
* -2 -1 0
* -1 1 1
* 0 1 2
*
* Before returning the image, the corresponding tensor should be clamped in [0,255]
*
* @return returns a new DAISGram containing the modified object
*/
DAISGram emboss() const;
/**
* Smooth the image
*
* This function remove the noise in an image using convolution and an average filter
* of size h*h:
*
* c = 1/(h*h)
*
* filter[3][3]
* c c c
* c c c
* c c c
*
* @param h the size of the filter
* @return returns a new DAISGram containing the modified object
*/
DAISGram smooth(int h = 3) const;
/**
* Edges of an image
*
* This function extract the edges of an image by using the convolution
* operator and the following filter
*
*
* filter[3][3]
* -1 -1 -1
* -1 8 -1
* -1 -1 -1
*
* Remeber to convert the image to grayscale before running the convolution.
*
* Before returning the image, the corresponding tensor should be clamped in [0,255]
*
* @return returns a new DAISGram containing the modified object
*/
DAISGram edge() const;
/**
* Blend with anoter image
*
* This function generate a new DAISGram which is the composition
* of the object and another DAISGram object
*
* The composition follows this convex combination:
* results = alpha*this + (1-alpha)*rhs
*
* rhs and this obejct MUST have the same dimensions.
*
* @param rhs The second image involved in the blending
* @param alpha The parameter of the convex combination
* @return returns a new DAISGram containing the blending of the two images.
*/
DAISGram blend(const DAISGram& rhs, float alpha = 0.5) const;
/**
* Green Screen
*
* This function substitutes a pixel with the corresponding one in a background image
* if its colors are in the surrounding (+- threshold) of a given color (rgb).
*
* (rgb - threshold) <= pixel <= (rgb + threshold)
*
*
* @param bkg The second image used as background
* @param rgb[] The color to substitute (rgb[0] = RED, rgb[1]=GREEN, rgb[2]=BLUE)
* @param threshold[] The threshold to add/remove for each color (threshold[0] = RED, threshold[1]=GREEN, threshold[2]=BLUE)
* @return returns a new DAISGram containing the result.
*/
DAISGram greenscreen(DAISGram& bkg, int rgb[], float threshold[]) const;
/**
* Equalize
*
* Stretch the distribution of colors of the image in order to use the full range of intesities.
*
* See https://it.wikipedia.org/wiki/Equalizzazione_dell%27istogramma
*
* @return returns a new DAISGram containing the equalized image.
*/
DAISGram equalize() const;
/**
* Generate Random Image
*
* Generate a random image from nois
*
* @param h height of the image
* @param w width of the image
* @param d number of channels
* @return returns a new DAISGram containing the generated image.
*/
void generate_random(int h, int w, int d);
//------------------------ FUNZIONI DI UTILITY AGGIUNTIVE -------------------------------
/**
* operatore che permette di confrontare due immagini usando l'operator == tra i relativi tensori
*
* @param rhs
* @return true if equals
* @return false if not equals
*/
bool operator==(const DAISGram& rhs) const;
/**
* metodo usato per fare il round dei dati del tensore dell'immagine
* necessario in fase di test per verificare l'effettiva correttezza
* del risultato rispetto a quello datoci dal professore
*
* @return DAISGram
*/
DAISGram round() const;
/**
* salva il tensore dell'immagine su file
*
* @param filename
*/
void save_tensor_to_file(string filename) const;
//------------------------- FUNZIONI AGGIUNTIVE PER LA MANIPOLAZIONE DI IMMAGINI --------------------------
/**
* implementazione del filtro sobel (verticale o orizzontale)
* utile per il riconiscimento dei contorni
*
* @param horizontal
* @return DAISGram
*/
DAISGram sobel(bool horizontal = true) const;
/**
* implementazione completa del filtro sobel data dall'unione del sobel verticale con quello
* orizzontale (calcolando la norma pixel per pixel dei due)
*
* @return DAISGram
*/
DAISGram full_sobel() const;
/**
* specchia l'immagine verticalmente o orizzontalmente
*
* @param vertical
* @return DAISGram
*/
DAISGram flip(bool vertical = true) const;
/**
* inverte i colori dell'immagine
*
* @return DAISGram
*/
DAISGram invert_colours() const;
/**
* converte l'encoding dell'immagine da RGB a HSV (hue, saturation, value)
* usata per equalizzare le immagini colorate
*
* @return DAISGram
*/
DAISGram convert_rgb_to_hsv() const;
/**
* converte l'encoding dell'immagine da HSV a RGB
*
* @return DAISGram
*/
DAISGram convert_hsv_to_rgb() const;
/**
* equalizzazione per le immagini colorate, il metodo converte l'immagine in formato HSV
* e esegue l'equalizzazione sul canale value e infine riconverte l'immagine in formato RGB,
* ciò permette una più corretta equalizzazione dei colori.
*
* @return DAISGram
*/
DAISGram color_equalize() const;
/**
* riduce la risoluzione dell'immagine rendendola più "pixellosa"
*
* @param pixels
* @return DAISGram
*/
DAISGram pixelate(int pixels = 8) const;
/**
* riproduce l'immagine usando caratteri ascii e la salva su un file .txt
*
* @param filename
*/
void asciiArt(string filename) const;
};
#endif