1d08c377
David Mayerich
added grids subdi...
|
1
2
3
|
#ifndef STIM_IMAGE_STACK_H
#define STIM_IMAGE_STACK_H
|
8b7be670
David Mayerich
implemented savin...
|
4
5
|
#include "../parser/wildcards.h"
#include "../parser/filename.h"
|
ad4a30c5
David Mayerich
changed grid_data...
|
6
|
#include "../grids/grid.h"
|
8b7be670
David Mayerich
implemented savin...
|
7
|
#include "../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;
|
1d08c377
David Mayerich
added grids subdi...
|
24
|
|
8157c392
David Mayerich
added parser and ...
|
25
26
|
public:
|
ae407376
David Mayerich
added support for...
|
27
28
29
|
///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...
|
30
31
32
33
34
35
36
37
38
39
40
|
void load_images(std::string file_mask){
stim::filename file_path(file_mask);
//if the file path is relative, update it with the current working directory
if(file_path.is_relative()){
stim::filename wd = stim::filename::cwd();
file_path = wd.get_relative(file_mask);
}
//get the list of files
|
445d9db7
David Mayerich
fixed directory e...
|
41
|
std::vector<stim::filename> file_list = file_path.get_list();
|
5cda84ab
David Mayerich
putting pranathi ...
|
42
43
44
45
46
47
|
//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);
}
|
8b7be670
David Mayerich
implemented savin...
|
48
49
|
//load the first image and set all of the image_stack properties
|
445d9db7
David Mayerich
fixed directory e...
|
50
|
std::cout<<"File to Load: "<<file_list[0].str()<<std::endl;
|
8b7be670
David Mayerich
implemented savin...
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
stim::image<T> I(file_list[0].str());
//set the image resolution and number of channels
R[0] = I.channels();
R[1] = I.width();
R[2] = I.height();
R[3] = file_list.size();
//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++){
//load the image
stim::image<T> I(file_list[i].str());
//retrieve the interlaced data from the image - store it in the grid
I.data_interleaved(&ptr[ i * R[0] * R[1] * R[2] ]);
}
}
|
ae407376
David Mayerich
added support for...
|
73
74
75
76
|
///Saves a single page to an image file
/// @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 ...
|
77
78
79
80
81
82
83
84
85
86
|
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
I.set_interleaved(&ptr[ i * R[0] * R[1] * R[2] ], R[1], R[2], R[0]);
I.save(file_name);
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
87
88
89
90
91
92
93
94
95
96
97
98
99
|
///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...
|
100
101
102
|
///Saves the entire stack to a set of images
/// @param file_mask is the mask describing how the file names will be saved (ex. image????.bmp)
|
8b7be670
David Mayerich
implemented savin...
|
103
104
105
106
107
108
109
110
111
112
113
114
115
|
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
if(file_path.is_relative()){
stim::filename wd = stim::filename::cwd();
file_path = wd.get_relative(file_mask);
}
//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 ...
|
116
117
118
|
for(int i=0; i<R[3]; i++)
save_image(file_list[i], i);
}
|
8b7be670
David Mayerich
implemented savin...
|
119
|
|
1d08c377
David Mayerich
added grids subdi...
|
120
121
122
123
124
|
};
}
|
8b7be670
David Mayerich
implemented savin...
|
125
|
#endif
|