rolling_normalization.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #include <swri_image_util/rolling_normalization.h>
00031 
00032 namespace swri_image_util
00033 {
00034   RollingNormalization::RollingNormalization(int32_t size) :
00035     max_size_(size),
00036     samples_(0)
00037   {
00038     
00039   }
00040   
00041   RollingNormalization::~RollingNormalization()
00042   {
00043   
00044   }
00045     
00046   cv::Mat RollingNormalization::AddSample(const cv::Mat& image)
00047   {
00048     if (samples_ == 0)
00049     {
00050       image.convertTo(average_image_, CV_64F, 1.0, 0.0);
00051     }
00052     else
00053     {
00054       cv::Mat temp;
00055       image.convertTo(temp, CV_64F, 1.0, 0.0);
00056       double s = static_cast<double>(samples_);
00057       average_image_ = (average_image_ * s + temp) / (s + 1.0);
00058     }
00059     
00060     samples_++;
00061     if (samples_ > max_size_)
00062     {
00063       samples_ = max_size_;
00064     }
00065     
00066     cv::Mat mean_image;
00067     average_image_.convertTo(mean_image, CV_8U);
00068     cv::Mat temp_norm_image;
00069 
00070     cv::medianBlur(mean_image, temp_norm_image, 25);
00071 
00072     cv::Mat temp_norm_image2;
00073     temp_norm_image.convertTo(temp_norm_image2, CV_32F);
00074     double max1 = 0;
00075     for (int32_t i = 0; i < temp_norm_image2.rows; i++)
00076     {
00077       for (int32_t j = 0; j < temp_norm_image2.cols; j++)
00078       {
00079         if (temp_norm_image2.at<float>(i, j) > max1)
00080         {
00081           max1 = temp_norm_image2.at<float>(i, j);
00082         }
00083       }
00084     }
00085 
00086     temp_norm_image2 = temp_norm_image2 * (255.0 / max1);
00087 
00088     cv::Mat temp_norm_image3;
00089     temp_norm_image2.convertTo(temp_norm_image3, CV_8U, 1.0, 0.0);
00090 
00091 
00092     cv::GaussianBlur(temp_norm_image3,
00093                      norm_image_,
00094                      cv::Size(15, 15),
00095                      5,
00096                      5);
00097     return norm_image_;
00098   }
00099 }


swri_image_util
Author(s): Kris Kozak
autogenerated on Tue Oct 3 2017 03:19:34