[a34150]: contrib / brl / bpro / core / vil_pro / processes / vil_mask_image_using_ids_process.cxx Maximize Restore History

Download this file

vil_mask_image_using_ids_process.cxx    75 lines (63 with data), 2.4 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This is brl/bpro/core/vil_pro/processes/vil_mask_image_using_ids_process.cxx
#include <bprb/bprb_func_process.h>
//:
// \file Mask all ids except the given one in an image using another id image (should be exactly same size)
#include "../vil_math_functors.h"
#include <vil/vil_convert.h>
#include <bprb/bprb_parameters.h>
#include <vcl_iostream.h>
#include <vcl_string.h>
#include <vil/vil_image_view_base.h>
#include <vil/vil_transform.h>
#include <vil/vil_math.h>
//: Constructor
bool vil_mask_image_using_ids_process_cons(bprb_func_process& pro)
{
//input
bool ok=false;
vcl_vector<vcl_string> input_types;
input_types.push_back("vil_image_view_base_sptr"); // input
input_types.push_back("vil_image_view_base_sptr"); // mask image
input_types.push_back("unsigned"); // input id (all the other ids will be masked)
ok = pro.set_input_types(input_types);
if (!ok) return ok;
//output
vcl_vector<vcl_string> output_types;
output_types.push_back("vil_image_view_base_sptr"); // output
ok = pro.set_output_types(output_types);
if (!ok) return ok;
return true;
}
//: Execute the process
bool vil_mask_image_using_ids_process(bprb_func_process& pro)
{
// Sanity check
if (pro.n_inputs()< 3) {
vcl_cout << "vil_map_image_binary_process: The input number should be 3" << vcl_endl;
return false;
}
unsigned i=0;
vil_image_view_base_sptr image_sptr = pro.get_input<vil_image_view_base_sptr>(i++);
vil_image_view_base_sptr mask_image_sptr = pro.get_input<vil_image_view_base_sptr>(i++);
unsigned idi = pro.get_input<unsigned>(i++);
unsigned char id = (unsigned char)idi;
unsigned ni = image_sptr->ni();
unsigned nj = image_sptr->nj();
if (ni != mask_image_sptr->ni() || nj != mask_image_sptr->nj()) {
vcl_cerr << "In vil_mask_image_using_ids_process() - incompatible input images!\n";
return false;
}
vil_image_view<float> image(image_sptr);
vil_image_view<vxl_byte> mask_image(mask_image_sptr);
vil_image_view<float> out_image(ni, nj);
out_image.fill(-100000);
vil_image_view<float> dest(ni, nj);
for (unsigned i = 0; i < ni; i++)
for (unsigned j = 0; j < nj; j++) {
if (id == mask_image(i,j))
out_image(i,j) = image(i,j);
}
vil_image_view_base_sptr out_image_sptr = new vil_image_view<float>(out_image);
pro.set_output_val<vil_image_view_base_sptr>(0, out_image_sptr);
return true;
}