1d08c377
David Mayerich
added grids subdi...
|
1
2
3
|
#ifndef STIM_IMAGE_STACK_H
#define STIM_IMAGE_STACK_H
|
ae05c3e4
Pavel Govyadinov
Found an error wi...
|
4
5
6
7
|
#include <stim/parser/wildcards.h>
#include <stim/parser/filename.h>
#include <stim/grids/grid.h>
#include <stim/image/image.h>
|
1d08c377
David Mayerich
added grids subdi...
|
8
9
10
|
namespace stim{
|
ae407376
David Mayerich
added support for...
|
11
12
13
|
/**This class is used to load 3D grid data from stacks of images
The class uses a 4D grid object, where the first dimension is a color value.
**/
|
1d08c377
David Mayerich
added grids subdi...
|
14
|
template<typename T>
|
ad4a30c5
David Mayerich
changed grid_data...
|
15
|
class image_stack : public virtual stim::grid<T, 4>{
|
8b7be670
David Mayerich
implemented savin...
|
16
17
18
19
|
enum image_type {stimAuto, stimMono, stimRGB, stimRGBA};
protected:
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
20
|
using stim::grid<T, 4>::S;
|
ad4a30c5
David Mayerich
changed grid_data...
|
21
22
23
|
using stim::grid<T, 4>::R;
using stim::grid<T, 4>::ptr;
using stim::grid<T, 4>::samples;
|
945ee13c
Laila Saadatifard
the get_list func...
|
24
|
using stim::grid<T, 4>::read;
|
1d08c377
David Mayerich
added grids subdi...
|
25
|
|
8157c392
David Mayerich
added parser and ...
|
26
27
|
public:
|
ae407376
David Mayerich
added support for...
|
28
29
30
|
///Load an image stack based on a file mask. Images are loaded in alphanumeric order.
/// @param file_mask is the mask describing images to be loaded
|
8b7be670
David Mayerich
implemented savin...
|
31
32
33
34
|
void load_images(std::string file_mask){
stim::filename file_path(file_mask);
|
8b7be670
David Mayerich
implemented savin...
|
35
|
//get the list of files
|
445d9db7
David Mayerich
fixed directory e...
|
36
|
std::vector<stim::filename> file_list = file_path.get_list();
|
5cda84ab
David Mayerich
putting pranathi ...
|
37
38
39
40
41
42
|
//if there are no matching files, exit
if(file_list.size() == 0){
std::cout<<"STIM ERROR (image_stack): No matching files for loading a stack."<<std::endl;
exit(1);
}
|
34ec8a82
David Mayerich
added comments
|
43
44
|
//for(int i = 0; i < file_list.size(); i++)
// std::cout << file_list[i].str() << std::endl;
|
8b7be670
David Mayerich
implemented savin...
|
45
46
|
//load the first image and set all of the image_stack properties
|
8b7be670
David Mayerich
implemented savin...
|
47
48
49
|
stim::image<T> I(file_list[0].str());
//set the image resolution and number of channels
|
5eeaf941
Pavel Govyadinov
changer to the ba...
|
50
51
52
53
|
R.push(I.channels());
R.push(I.width());
R.push(I.height());
R.push(file_list.size());
|
8b7be670
David Mayerich
implemented savin...
|
54
55
56
57
58
59
|
//allocate storage space
ptr = (T*)malloc(sizeof(T) * samples());
//load and copy each image into the grid
for(unsigned int i = 0; i<R[3]; i++){
|
8b7be670
David Mayerich
implemented savin...
|
60
61
62
63
|
//load the image
stim::image<T> I(file_list[i].str());
//retrieve the interlaced data from the image - store it in the grid
|
9b766f1f
Pavel Govyadinov
completed merge f...
|
64
|
I.get_interleaved_rgb(&ptr[ i * R[0] * R[1] * R[2] ]);
|
945ee13c
Laila Saadatifard
the get_list func...
|
65
|
|
8b7be670
David Mayerich
implemented savin...
|
66
67
68
|
}
}
|
ae05c3e4
Pavel Govyadinov
Found an error wi...
|
69
70
71
72
73
74
75
|
///Inserts image I into slot i.
/// @param stim::image<T> I; image to insert.
/// @int I, where to place the image.
void insert_image(stim::image<T> I, int i)
{
I.get_interleaved_rgb(&ptr[i *R[0] *R[1] *R[2] ]);
}
|
ae407376
David Mayerich
added support for...
|
76
|
|
ae05c3e4
Pavel Govyadinov
Found an error wi...
|
77
|
///Saves a single page to an image file
|
ae407376
David Mayerich
added support for...
|
78
79
|
/// @param file_name is the name of the image file to be created
/// @param i is the page to be saved
|
6156690f
David Mayerich
added ability to ...
|
80
81
82
83
84
85
|
void save_image(std::string file_name, unsigned int i){
//create an image
stim::image<T> I;
//retrieve the interlaced data from the image - store it in the grid
|
ae05c3e4
Pavel Govyadinov
Found an error wi...
|
86
|
I.set_interleaved_rgb(&ptr[ i * R[0] * R[1] * R[2] ], R[1], R[2], R[0]);
|
6156690f
David Mayerich
added ability to ...
|
87
88
89
|
I.save(file_name);
}
|
ae05c3e4
Pavel Govyadinov
Found an error wi...
|
90
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
91
92
93
94
95
96
97
98
99
100
101
102
103
|
///Sets the dimensions of the image in each direction
///Voxel-size.
/// @param x size in the x direction
/// @param y size in the y direction
/// @param z size in the z direction
void
set_dim(float x, float y, float z)
{
S[0] = 1;
S[1] = x;
S[2] = y;
S[3] = z;
}
|
ae407376
David Mayerich
added support for...
|
104
|
|
ae05c3e4
Pavel Govyadinov
Found an error wi...
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
///set dimensions of the grid.
/// @param channels, number of channels in each image.
/// @param width, number of pixels in width each image.
/// @param height, number of pixels in height.
/// @param depth, number of pixels in depth.
void init(int channels, int width, int height, int depth)
{
R.resize(4);
R[0] = channels;
R[1] = width;
R[2] = height;
R[3] = depth;
ptr = (T*)malloc(sizeof(T) * samples());
}
///Saves the entire stack to a set of images
|
ae407376
David Mayerich
added support for...
|
122
|
/// @param file_mask is the mask describing how the file names will be saved (ex. image????.bmp)
|
8b7be670
David Mayerich
implemented savin...
|
123
124
125
126
127
|
void save_images(std::string file_mask){
stim::filename file_path(file_mask);
//if the file path is relative, update it with the current working directory
|
7ada0a48
Pavel Govyadinov
fixed the bugs wi...
|
128
129
130
131
|
// if(file_path.is_relative()){
// stim::filename wd = stim::filename::cwd();
// file_path = wd.get_relative(file_mask);
// }
|
8b7be670
David Mayerich
implemented savin...
|
132
133
134
135
|
//create a list of file names
std::vector<std::string> file_list = stim::wildcards::increment(file_path.str(), 0, R[3]-1, 1);
|
6156690f
David Mayerich
added ability to ...
|
136
137
138
|
for(int i=0; i<R[3]; i++)
save_image(file_list[i], i);
}
|
8b7be670
David Mayerich
implemented savin...
|
139
|
|
945ee13c
Laila Saadatifard
the get_list func...
|
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/// Returns the pixel at the specified point
T get(unsigned int x, unsigned int y, unsigned int z, unsigned int c = 0){
return ptr[z * R[0] * R[1] * R[2] + y * R[0] * R[1] + x * R[0] + c];
}
void read(std::string file, unsigned int X, unsigned int Y, unsigned int Z, unsigned int C = 1, unsigned int header = 0){
read(file, stim::vec<unsigned long>(C, X, Y, Z), header);
}
T* data(){
return ptr;
}
|
1d08c377
David Mayerich
added grids subdi...
|
153
154
155
156
157
|
};
}
|
8b7be670
David Mayerich
implemented savin...
|
158
|
#endif
|