Skip to content

Commit

Permalink
Merge pull request #1 from ntnu-arl/feature/opencv4
Browse files Browse the repository at this point in the history
Feature/opencv4
  • Loading branch information
fmascarich authored Feb 10, 2021
2 parents c99da43 + ce67a88 commit acecbb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/dehaze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace dehaze
{

static cv::Mat boxfilter(const cv::Mat &I, int r)
{
cv::Mat result;
Expand Down Expand Up @@ -87,8 +87,8 @@ namespace dehaze
void CHazeRemoval::get_dark_channel()
{
m_light_pixel_vect.clear();
cv::resize(m_in_frame, m_dark_ch_resized_i, m_dark_ch_resized_i.size(), 0, 0, CV_INTER_NN);
/*
cv::resize(m_in_frame, m_dark_ch_resized_i, m_dark_ch_resized_i.size(), 0, 0, cv::INTER_NEAREST);
/*
1. Iterate over each pixel and save the smallest rgb vals for each pixel in pix_mins
2. Iterate over each pixel, Iterate over that pixel's row neighbors, save the smallest value in row_mins
3. Iterate over each pixel, Iterate over that pixel's column neighbors, save the smallest value in the light_pixels_vector
Expand Down Expand Up @@ -131,7 +131,7 @@ namespace dehaze
for (int i = 0; i < m_dark_ch_resized_i.rows; ++i)
{
for (int j = 0; j < m_dark_ch_resized_i.cols; ++j)
{
{
int cmin = cv::max(0, j - m_dehaze_radius);
int cmax = cv::min(j + m_dehaze_radius, m_dark_ch_resized_i.cols - 1);
float min_val = 255.0f;
Expand Down Expand Up @@ -168,7 +168,7 @@ namespace dehaze
}
void CHazeRemoval::get_transmission()
{
cv::resize(m_in_frame, m_transmission_resized_i, m_transmission_resized_i.size(), 0, 0, CV_INTER_NN);
cv::resize(m_in_frame, m_transmission_resized_i, m_transmission_resized_i.size(), 0, 0, cv::INTER_NEAREST);
// pre calculate the minimum pixel values for each pixel, so they're calculated n times, not n*m times
unsigned long int pix_idx = 0;
for (int i = 0; i < m_transmission_resized_i.rows; ++i)
Expand Down Expand Up @@ -220,7 +220,7 @@ namespace dehaze
m_transmission_resized_result.ptr<float>(i)[j] = 1.0f - m_omega * min_val;
}
}
cv::resize(m_transmission_resized_result, m_cv_mat_transmission, m_in_frame.size(), 0,0, CV_INTER_LINEAR);
cv::resize(m_transmission_resized_result, m_cv_mat_transmission, m_in_frame.size(), 0,0, cv::INTER_LINEAR);
}
void CHazeRemoval::guided_filter()
{
Expand All @@ -241,4 +241,4 @@ namespace dehaze
m_cv_mat_recover_result = cv::min(m_cv_mat_recover_result, 255.0);
m_cv_mat_recover_result = cv::max(m_cv_mat_recover_result, 0.0);
}
} // namespace dehaze
} // namespace dehaze
16 changes: 8 additions & 8 deletions src/guided_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void GuidedFilterColor::filter(const cv::Mat &I, const cv::Mat &p, cv::Mat &resu
I.convertTo(reformated_I, CV_32F);
else
reformated_I = I.clone();
cv::resize(reformated_I, resized_I, m_resized_size, 0, 0, CV_INTER_NN); // NN recommended by matlab code
cv::resize(reformated_I, resized_I, m_resized_size, 0, 0, cv::INTER_NEAREST); // NN recommended by matlab code

m_original_I_depth = resized_I.depth();

Expand All @@ -68,11 +68,11 @@ void GuidedFilterColor::filter(const cv::Mat &I, const cv::Mat &p, cv::Mat &resu
boxfilter(Ichannels[2], mean_I_b, m_sub_radius);

boxfilter(Ichannels[0].mul(Ichannels[0]), var_I_rr, m_sub_radius);
boxfilter(Ichannels[0].mul(Ichannels[1]), var_I_rg, m_sub_radius);
boxfilter(Ichannels[0].mul(Ichannels[2]), var_I_rb, m_sub_radius);
boxfilter(Ichannels[1].mul(Ichannels[1]), var_I_gg, m_sub_radius);
boxfilter(Ichannels[1].mul(Ichannels[2]), var_I_gb, m_sub_radius);
boxfilter(Ichannels[2].mul(Ichannels[2]), var_I_bb, m_sub_radius);
boxfilter(Ichannels[0].mul(Ichannels[1]), var_I_rg, m_sub_radius);
boxfilter(Ichannels[0].mul(Ichannels[2]), var_I_rb, m_sub_radius);
boxfilter(Ichannels[1].mul(Ichannels[1]), var_I_gg, m_sub_radius);
boxfilter(Ichannels[1].mul(Ichannels[2]), var_I_gb, m_sub_radius);
boxfilter(Ichannels[2].mul(Ichannels[2]), var_I_bb, m_sub_radius);

var_I_rr = var_I_rr - mean_I_r.mul(mean_I_r) + m_eps;
var_I_rg = var_I_rg - mean_I_r.mul(mean_I_g);
Expand All @@ -97,7 +97,7 @@ void GuidedFilterColor::filter(const cv::Mat &I, const cv::Mat &p, cv::Mat &resu
invgb /= covDet;
invbb /= covDet;

cv::resize(p, resized_p, m_resized_size, 0, 0, CV_INTER_NN);
cv::resize(p, resized_p, m_resized_size, 0, 0, cv::INTER_NEAREST);

boxfilter(resized_p, mean_p, m_sub_radius);

Expand Down Expand Up @@ -125,5 +125,5 @@ void GuidedFilterColor::filter(const cv::Mat &I, const cv::Mat &p, cv::Mat &resu
boxfilter(b, temp, m_sub_radius);
result += temp;

cv::resize(result, result, m_original_image_size, 0,0, CV_INTER_NN);
cv::resize(result, result, m_original_image_size, 0,0, cv::INTER_NEAREST);
}

0 comments on commit acecbb9

Please sign in to comment.