MCPcopy Create free account
hub / github.com/LBANN/lbann / main

Function main

tools/compute_mean/uniform_mean.cpp:125–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124
125int main(int argc, char** argv) {
126 if ((argc < 2) || (7 < argc)) {
127 show_help(argv[0]);
128 return 0;
129 }
130
131 int width = 0; // The width of the output image
132 int height = 0; // The height of the output image
133 int num_channels = 0; // The number of channels of the output image
134 int in_depth = CV_8U; // The depth of the input pixel. The default is unsigned 8-bit [0 255]
135 cv::Mat mean_image; // The mean image to output
136 cv::Scalar pixel_m(0.0); // The mean pixel value (in double precision)
137 cv::Scalar pixel(0.0); // The pixel value converted to integers to populate the output image
138 int out_depth = CV_8U; // The depth of output image. The default is unsigned 8-bit [0 255]
139
140
141 if ((argc % 2) != 0) { // The depth code of output image is specified
142 out_depth = atoi(argv[argc-1]);
143 if ((out_depth != CV_8U) && (out_depth != CV_16U)) {
144 std::cerr << "Invalid opencv depth code: " << out_depth << std::endl;
145 return 0;
146 }
147 argc --; // so that the rest of argument parsing does not
148 // need to care of the presence of the optional argument
149 }
150
151 if (argc < 4) { // Given an image, compute the mean pixel value out of the input image
152 // Load the image
153 cv::Mat mean_image = read_image(argv[1]);
154 if (mean_image.empty()) {
155 std::cerr << "Could not read the image file: " << argv[1] << std::endl;
156 return 0;
157 }
158 width = mean_image.cols;
159 height = mean_image.rows;
160 num_channels = mean_image.channels();
161
162 // Compute the mean pixel of the input image, reducing to one value per channel
163 pixel_m = reduce_image(mean_image);
164
165 in_depth = mean_image.depth();
166 } else { // The pixel value is given
167 width = atoi(argv[1]);
168 height = atoi(argv[2]);
169 num_channels = argc - 3;
170
171 bool is_unit_scaled = true;
172
173 // Set the mean pixel value given in the command-line arguments
174 for (int c = 0; c < num_channels; ++c) {
175 pixel_m[c] = atof(argv[c+3]);
176 if ((pixel_m[c] < 0.0) || (std::numeric_limits<_depth_type(CV_8U)>::max() < pixel_m[c])) {
177 std::cerr << "Pixel value must be specified in the scale [0.0 255.0] or in the unit scale [0.0 1.0]";
178 return 0;
179 }
180 // Assume the unit scale if all the channel values are within the range [0.0 1.0]
181 if (1.0 < pixel_m[c]) is_unit_scaled = false;
182 }

Callers

nothing calls this directly

Calls 7

show_helpFunction · 0.85
read_imageFunction · 0.85
reduce_imageFunction · 0.85
scale_pixelFunction · 0.85
write_bin_imageFunction · 0.85
maxFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected