M include/parallaxis.hpp => include/parallaxis.hpp +7 -0
@@ 64,6 64,13 @@ cv::Mat load_image(std::vector<stdfs::path>& filenames, size_t& index);
+/** Perform all operations enabled in the options on the input image and return
+ * the resulting image.
+ */
+cv::Mat process_depth_image(const cv::Mat& input_image, const Options& options);
+
+
+
/** Given a path to a directory return a naturally sorted list of the files it
* contains.
*/
M src/parallaxis.cpp => src/parallaxis.cpp +51 -0
@@ 87,6 87,57 @@ cv::Mat load_image(std::vector<stdfs::path>& filenames, size_t& index) {
+cv::Mat process_depth_image(const cv::Mat& input_image, const Options& options) {
+ // Copy the input image
+ cv::Mat image;
+ input_image.copyTo(image);
+
+ // Histogram equalization
+ if (options.enable_normalization) {
+ const size_t max_value = (1 << 8 * image.elemSize1()) - 1;
+ if (options.common_normalization) {
+ const uint16_t range = options.global_max - options.global_min;
+ const float scale = static_cast<float>(max_value) / range;
+ image = scale * (image - options.global_min);
+ } else {
+ cv::normalize(image, image, 0, max_value, cv::NORM_MINMAX);
+ }
+ }
+
+ // Invert colors
+ if (options.invert_colors) {
+ // Use a mask to only invert valid depth measurements.
+ cv::Mat valid_depth_mask;
+ image.convertTo(valid_depth_mask, CV_8U, 1.0/UINT8_MAX);
+ cv::threshold(valid_depth_mask, valid_depth_mask,
+ 0, UINT8_MAX, cv::THRESH_BINARY);
+ cv::bitwise_not(image, image, valid_depth_mask);
+ }
+
+ // Use colormap
+ if (options.enable_colormap) {
+ cv::Mat image_8u;
+ image.convertTo(image_8u, CV_8U, 1.0/UINT8_MAX);
+
+ cv::Mat image_c;
+ cv::applyColorMap(image_8u, image_c, options.colormap);
+
+ // Set invalid depth measurements to black. Create a mask by
+ // converting the depth image into a binary image and inverting
+ // it.
+ cv::Mat invalid_depth_mask;
+ cv::threshold(image_8u, invalid_depth_mask,
+ 0, UINT8_MAX, cv::THRESH_BINARY_INV);
+ image_c.setTo(cv::Scalar(0, 0, 0), invalid_depth_mask);
+
+ image_c.copyTo(image);
+ }
+
+ return image;
+}
+
+
+
std::vector<stdfs::path> ls_directory(const stdfs::path& dir,
const bool recursive) {
M src/parallaxis_main.cpp => src/parallaxis_main.cpp +5 -44
@@ 45,51 45,9 @@ int main(int argc, char** argv) {
// Main image read/process/show loop.
while (not quit) {
cv::Mat image;
- original_image.copyTo(image);
-
// Only process grayscale images.
- if (image.channels() == 1) {
- // Histogram equalization.
- if (opts.enable_normalization) {
- const size_t max_value = (1 << 8 * image.elemSize1()) - 1;
- if (opts.common_normalization) {
- const uint16_t range = opts.global_max - opts.global_min;
- const float scale = static_cast<float>(max_value) / range;
- image = scale * (image - opts.global_min);
- } else {
- cv::normalize(image, image, 0, max_value, cv::NORM_MINMAX);
- }
- }
-
- // Invert colors.
- if (opts.invert_colors) {
- // Use a mask to only invert valid depth measurements.
- cv::Mat valid_depth_mask;
- image.convertTo(valid_depth_mask, CV_8U, 1.0/UINT8_MAX);
- cv::threshold(valid_depth_mask, valid_depth_mask,
- 0, UINT8_MAX, cv::THRESH_BINARY);
-
- cv::bitwise_not(image, image, valid_depth_mask);
- }
-
- // Use colormap.
- if (opts.enable_colormap) {
- cv::Mat image_8u;
- image.convertTo(image_8u, CV_8U, 1.0/UINT8_MAX);
-
- cv::Mat image_c;
- cv::applyColorMap(image_8u, image_c, opts.colormap);
-
- // Set invalid depth measurements to black. Create a mask by
- // converting the depth image into a binary image and inverting
- // it.
- cv::Mat invalid_depth_mask;
- cv::threshold(image_8u, invalid_depth_mask,
- 0, UINT8_MAX, cv::THRESH_BINARY_INV);
- image_c.setTo(cv::Scalar(0, 0, 0), invalid_depth_mask);
-
- image_c.copyTo(image);
- }
+ if (original_image.channels() == 1) {
+ image = process_depth_image(original_image, opts);
} else {
// Skip non-grayscale images.
if (opts.only_grayscale) {
@@ 105,6 63,9 @@ int main(int argc, char** argv) {
exit(EXIT_FAILURE);
}
continue;
+ } else {
+ // Show the RGB image as-is
+ original_image.copyTo(image);
}
}