1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26
27 #include <cstdio>
28
29 #include <Core/Core.h>
30 #include <IO/IO.h>
31
main(int argc,char ** argv)32 int main(int argc, char **argv)
33 {
34 using namespace three;
35
36 SetVerbosityLevel(VerbosityLevel::VerboseAlways);
37
38 if (argc != 3) {
39 PrintInfo("Open3D %s\n", OPEN3D_VERSION);
40 PrintInfo("\n");
41 PrintInfo("Usage:\n");
42 PrintInfo(" > TestImage [image filename] [depth filename]\n");
43 PrintInfo(" The program will :\n");
44 PrintInfo(" 1) Read 8bit RGB and 16bit depth image\n");
45 PrintInfo(" 2) Convert RGB image to single channel float image\n");
46 PrintInfo(" 3) 3x3, 5x5, 7x7 Gaussian filters are applied\n");
47 PrintInfo(" 4) 3x3 Sobel filter for x-and-y-directions are applied\n");
48 PrintInfo(" 5) Make image pyramid that includes Gaussian blur and downsampling\n");
49 PrintInfo(" 6) Will save all the layers in the image pyramid\n");
50 return 0;
51 }
52
53 const std::string filename_rgb(argv[1]);
54 const std::string filename_depth(argv[2]);
55
56 Image color_image_8bit;
57 if (ReadImage(filename_rgb, color_image_8bit)) {
58
59 PrintDebug("RGB image size : %d x %d\n",
60 color_image_8bit.width_, color_image_8bit.height_);
61 auto gray_image = CreateFloatImageFromImage(color_image_8bit);
62 WriteImage("gray.png",
63 *CreateImageFromFloatImage<uint8_t>(*gray_image));
64
65 PrintDebug("Gaussian Filtering\n");
66 auto gray_image_b3 = FilterImage(*gray_image,
67 Image::FilterType::Gaussian3);
68 WriteImage("gray_blur3.png",
69 *CreateImageFromFloatImage<uint8_t>(*gray_image_b3));
70 auto gray_image_b5 = FilterImage(*gray_image,
71 Image::FilterType::Gaussian5);
72 WriteImage("gray_blur5.png",
73 *CreateImageFromFloatImage<uint8_t>(*gray_image_b5));
74 auto gray_image_b7 = FilterImage(*gray_image,
75 Image::FilterType::Gaussian7);
76 WriteImage("gray_blur7.png",
77 *CreateImageFromFloatImage<uint8_t>(*gray_image_b7));
78
79 PrintDebug("Sobel Filtering\n");
80 auto gray_image_dx = FilterImage(*gray_image,
81 Image::FilterType::Sobel3Dx);
82 // make [-1,1] to [0,1].
83 LinearTransformImage(*gray_image_dx, 0.5, 0.5);
84 ClipIntensityImage(*gray_image_dx);
85 WriteImage("gray_sobel_dx.png",
86 *CreateImageFromFloatImage<uint8_t>(*gray_image_dx));
87 auto gray_image_dy = FilterImage(*gray_image,
88 Image::FilterType::Sobel3Dy);
89 LinearTransformImage(*gray_image_dy, 0.5, 0.5);
90 ClipIntensityImage(*gray_image_dy);
91 WriteImage("gray_sobel_dy.png",
92 *CreateImageFromFloatImage<uint8_t>(*gray_image_dy));
93
94 PrintDebug("Build Pyramid\n");
95 auto pyramid = CreateImagePyramid(*gray_image, 4);
96 for (int i = 0; i < 4; i++) {
97 auto level = pyramid[i];
98 auto level_8bit = CreateImageFromFloatImage<uint8_t>(*level);
99 std::string outputname =
100 "gray_pyramid_level" + std::to_string(i) + ".png";
101 WriteImage(outputname, *level_8bit);
102 }
103 } else {
104 PrintError("Failed to read %s\n\n", filename_rgb.c_str());
105 }
106
107 Image depth_image_16bit;
108 if (ReadImage(filename_depth, depth_image_16bit)) {
109
110 PrintDebug("Depth image size : %d x %d\n",
111 depth_image_16bit.width_, depth_image_16bit.height_);
112 auto depth_image = CreateFloatImageFromImage(depth_image_16bit);
113 WriteImage("depth.png",
114 *CreateImageFromFloatImage<uint16_t>(*depth_image));
115
116 PrintDebug("Gaussian Filtering\n");
117 auto depth_image_b3 = FilterImage(*depth_image,
118 Image::FilterType::Gaussian3);
119 WriteImage("depth_blur3.png",
120 *CreateImageFromFloatImage<uint16_t>(*depth_image_b3));
121 auto depth_image_b5 = FilterImage(*depth_image,
122 Image::FilterType::Gaussian5);
123 WriteImage("depth_blur5.png",
124 *CreateImageFromFloatImage<uint16_t>(*depth_image_b5));
125 auto depth_image_b7 = FilterImage(*depth_image,
126 Image::FilterType::Gaussian7);
127 WriteImage("depth_blur7.png",
128 *CreateImageFromFloatImage<uint16_t>(*depth_image_b7));
129
130 PrintDebug("Sobel Filtering\n");
131 auto depth_image_dx = FilterImage(*depth_image,
132 Image::FilterType::Sobel3Dx);
133 // make [-65536,65536] to [0,13107.2]. // todo: need to test this
134 LinearTransformImage(*depth_image_dx, 0.1, 6553.6);
135 ClipIntensityImage(*depth_image_dx, 0.0, 13107.2);
136 WriteImage("depth_sobel_dx.png",
137 *CreateImageFromFloatImage<uint16_t>(*depth_image_dx));
138 auto depth_image_dy = FilterImage(*depth_image,
139 Image::FilterType::Sobel3Dy);
140 LinearTransformImage(*depth_image_dy, 0.1, 6553.6);
141 ClipIntensityImage(*depth_image_dx, 0.0, 13107.2);
142 WriteImage("depth_sobel_dy.png",
143 *CreateImageFromFloatImage<uint16_t>(*depth_image_dy));
144
145 PrintDebug("Build Pyramid\n");
146 auto pyramid = CreateImagePyramid(*depth_image, 4);
147 for (int i = 0; i < 4; i++) {
148 auto level = pyramid[i];
149 auto level_16bit = CreateImageFromFloatImage<uint16_t>(*level);
150 std::string outputname =
151 "depth_pyramid_level" + std::to_string(i) + ".png";
152 WriteImage(outputname, *level_16bit);
153 }
154 }
155 else {
156 PrintError("Failed to read %s\n\n", filename_depth.c_str());
157 }
158
159 return 0;
160 }
161