forked from new299/DS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathds_isolate.cpp
More file actions
54 lines (39 loc) · 1.97 KB
/
Copy pathds_isolate.cpp
File metadata and controls
54 lines (39 loc) · 1.97 KB
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
#include "Image.h"
using namespace std;
int main(int argc, char* argv[]) {
cout << "ds_isolate <input image> <output directory> <subtracted image>" << endl;
cout << "argc: " << argc << endl;
string input_image_filename = argv[1];
string output_directory = argv[2];
string subtracted_image_filename;
if(argc > 3) subtracted_image_filename = argv[3];
Image input;
input.load_tiff(input_image_filename);
map<uint32_t,int> pixels1 = input.random_walk_collect(20 , 20,50000000,10);
map<uint32_t,int> pixels2 = input.random_walk_collect(input.m_width-20, 20,50000000,10);
map<uint32_t,int> pixels3 = input.random_walk_collect( 20,input.m_height-20,50000000,10);
map<uint32_t,int> pixels4 = input.random_walk_collect(input.m_width-20,input.m_height-20,50000000,10);
map<uint32_t,int> pixels; // = input.random_walk_collect(20,20,1000000000,10);
pixels.insert(pixels1.begin(),pixels1.end());
pixels.insert(pixels2.begin(),pixels2.end());
pixels.insert(pixels3.begin(),pixels3.end());
pixels.insert(pixels4.begin(),pixels4.end());
cerr << "Acquired " << pixels.size() << " during random walk" << endl;
pixels = grow_pixel_set(pixels,10);
cerr << "Grew pixel set to: " << pixels.size() << endl;
input.set_pixels(pixels,0,0);
input.remove_isolated_pixels(0);
if(subtracted_image_filename.length() != 0) input.save_tiff_rgb(subtracted_image_filename);
cerr << "Cleared background pixels, performing segmentation..." << endl;
vector<Image> fragments = input.segment_on_value(0);
// Create output directory folder
mkdir(output_directory.c_str(),0777);
cerr << "Saving fragments..." << endl;
for(size_t n=0;n<fragments.size();n++) {
if(fragments[n].pixel_count() > 20) {
string frag_dir = output_directory + string("/") + string("fragment_") + stringify(n);
mkdir(frag_dir.c_str(),0777);
fragments[n].save_tiff_rgb(frag_dir + string("/") + string("original.tif"));
}
}
}