Skip to content

fbs disparity filtering fix #1877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2018
Merged

fbs disparity filtering fix #1877

merged 5 commits into from
Nov 9, 2018

Conversation

ytyytyyt
Copy link
Contributor

@ytyytyyt ytyytyyt commented Nov 5, 2018

This pullrequest changes

  • Fixes Fast Bilateral Solver (FBS) disparity filtering demo, i.e. FBS works now with int16 disparity images
  • Revises data type handling for both input and confidence map images
  • Adds option to give command line arguments to FBS in addition to WLS
  • Moves Fast Global Smoothing (FGS) pre-filtering from fbs_filter.cpp to disparity_filtering.cpp demo code
force_builders=linux,docs,windows,macosx

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

uint16_t *pftar = (uint16_t*) output.data;
for (int i = 0; i < int(splat_idx.size()); i++)
{
pftar[i] = uint16_t(y(splat_idx[i]) * 65535.0f);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use cv::saturate_cast<ushort>(...) here and below.

xw = x.mul(w);
cv::ximgproc::fastGlobalSmootherFilter(guide, xw, filtered_xw, fgs_spatialSigma, fgs_colorSigma);
cv::ximgproc::fastGlobalSmootherFilter(guide, w, filtered_w, fgs_spatialSigma, fgs_colorSigma);
cv::divide(filtered_xw, filtered_w, filtered_disp, 1.0f, CV_32FC1);
cv::divide(filtered_xw, filtered_w+EPS, filtered_disp, 1.0f, CV_32FC1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some simple regression test to for this issue into test_fbs.cpp file.
New test images can be added into opencv_extra/testdata (but prefer to reuse existed).

Is it related for master branch only? Or 3.4 too? OpenCV handles division by zero differently for floating-point numbers (3.4 has zero pre-check, master uses IEEE 754 rules).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was related to master branch only as I was originally working with 3.4 and noticed the issue while switching to master. Like you pointed out, I had already a suspicion that the 3.4 handles division by zero differently but didn't check this.

Would it be better to remove the Fast Global Filtering because it is not used in the original paper for initializing the Fast Bilateral Solver? In fbs_filter.cpp, the parameters for FGS are also fixed. I would prefer to remove the FGS part and maybe add it to disparity filtering demo for comparison.

In the case, you think its better to keep the FGS in fbs_filter.cpp, I can add the requested test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not used in the original paper

It make sense to remove that.
From user/applications side it is more easy to add pre-filter than to remove extra stage.

@berak Do you have any objections?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, This code is not a part of any OpenCV release yet - you can work on 3.4 branch (3.4.4 expected on this week).

Copy link
Contributor

@berak berak Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no objections, wise decision ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In its present state, the fbs filter expects float confidence map values to be in [0,255] range like in disparity_filters.cpp. Would it be better to change the float confidence values to [0,1] range instead?

Besides this issue my revision should be complete.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float confidence values to [0,1] range

Sounds good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the FGS (i.e. WLS) filtering is moved from fbs_filter.cpp to disparity_filtering.cpp as a preprocessing option. Consequently, there is no division by zero issue even between master and 3.4 branches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alalek I added the fixed FBS filter to 3.4 branch (hopefully wasn't too late for 3.4.4).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some simple regression test to for this issue into test_fbs.cpp file.
New test images can be added into opencv_extra/testdata (but prefer to reuse existed).

I checked the test_fbs.cpp as well. It is comparing the output to a reference image produced with a different filter (FGS) with a very loose error threshold. I updated the test with a new reference image produced with the same filter and will commit it soon.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@alalek alalek merged commit 3f0eaf6 into opencv:master Nov 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants