Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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 }