-
Notifications
You must be signed in to change notification settings - Fork 8
/
DAISGram.cpp
76 lines (59 loc) · 1.68 KB
/
DAISGram.cpp
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
#include <iostream>
#include <string>
#include "dais_exc.h"
#include "tensor.h"
#include "libbmp.h"
#include "DAISGram.h"
using namespace std;
/**
* Load a bitmap from file
*
* @param filename String containing the path of the file
*/
void DAISGram::load_image(string filename){
BmpImg img = BmpImg();
img.read(filename.c_str());
const int h = img.get_height();
const int w = img.get_width();
data = Tensor(h, w, 3, 0.0);
for(int i=0;i<img.get_height();i++){
for(int j=0;j<img.get_width();j++){
data(i,j,0) = (float) img.red_at(j,i);
data(i,j,1) = (float) img.green_at(j,i);
data(i,j,2) = (float) img.blue_at(j,i);
}
}
}
/**
* 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 DAISGram::save_image(string filename){
data.clamp(0,255);
BmpImg img = BmpImg(getCols(), getRows());
img.init(getCols(), getRows());
for(int i=0;i<getRows();i++){
for(int j=0;j<getCols();j++){
img.set_pixel(j,i,(unsigned char) data(i,j,0),(unsigned char) data(i,j,1),(unsigned char) data(i,j,2));
}
}
img.write(filename);
}
/**
* 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 DAISGram::generate_random(int h, int w, int d){
data = Tensor(h,w,d,0.0);
data.init_random(128,50);
data.rescale(255);
}