Skip to content
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

[question] Masking throughout the whole pipeline #1261

Closed
isolin opened this issue Feb 8, 2021 · 14 comments
Closed

[question] Masking throughout the whole pipeline #1261

isolin opened this issue Feb 8, 2021 · 14 comments
Labels
stale for issues that becomes stale (no solution) type:question

Comments

@isolin
Copy link

isolin commented Feb 8, 2021

I saw several threads concerning masking. I am trying to accomplish a large scale reconstruction from various sources, with moving objects (persons, cars) and other objects (like my own capturing equipment) that need to be removed. If I don't remove them they already fool the SfM so much that it either fails or projects everything on a sphere-like surface. So manual masking up front is the only way to go for me.

Unfortunately, #1097 states it is not yet in the release. I tried to compile AliceVision on my own (Ubuntu) but ultimately failed. So I decided to create my own masking pipeline.

On input I have .png images with binary masks stored in the alpha channel.

  1. After FeatureExtraction I remove those features that overlap with the respective masked areas ✔️
  2. After DepthMapFilter I set masked regions of depth maps to -1, inspired by the script from Reconstruction "grows" artifacts into neutral background #566 ✔️
  3. Texturing still uses the masked parts producing a lot of artifacts

I started to thing about what I am doing wrong and I would appreciate help!

  1. hypothesis: As far as I can see there is no undistortion applied in the script of @ALfuhrmann. That might cause that mask does not fit well anymore. I will try to take that into account.
  2. hypothesis: What are the _simMap.exr and _nmodMap.png files? Should I apply masking to them as well?
  3. hypothesis: Is there anything else that would stop the Texturing node to sample the images in the masked regions?

Thank you for any help and suggestions.

@isolin
Copy link
Author

isolin commented Feb 8, 2021

Regarding undistortion, I found the folowing files: _P.txt that probably contains the projection matrix and _KRt.txt that is, I guess, the intrinsics matrix, rotation and translation?

I looked at the tutorial at OpenCV but I still can't figure out how use the information exported to the text files to undistort the masks.

dst = cv2.undistort(img, mtx, dist, None, newcameramtx)

I asusme that mtx is the projection matrix, newcameramtx is computed from it, but I don't know where to get the value of dist parameter.

@ALfuhrmann
Copy link

ALfuhrmann commented Feb 8, 2021 via email

@ALfuhrmann
Copy link

I asusme that mtx is the projection matrix, newcameramtx is computed from it, but I don't know where to get the value of dist parameter.

The "dist" parameter contains the distortion coefficients.
You can find the complete camera definition in the "cameras.sfm" file:

"intrinsics": [
{
"intrinsicId": "488010902",
"width": "3840",
"height": "2748",
"sensorWidth": "-1",
"sensorHeight": "-0.71562500000000007",
"serialNumber": "71052792",
"type": "radial3",
"initializationMode": "unknown",
"pxInitialFocalLength": "-1",
"pxFocalLength": "10191.437256657111",
"principalPoint": [
"1993.7472848550028",
"1389.9258887910489"
],
"distortionParams": [
"-0.26655085123583799",
"-0.65103106457375315",
"12.982983146989872"
],
"locked": "0"
},

@isolin
Copy link
Author

isolin commented Feb 8, 2021

Danke for the quick answer! 😄 Yes, in your workflow you generate the masks from undistorted images so they are already undistorted. But in my workflow

  • I need them already for sparse reconstruction
  • and they are hand-made

Since Meshroom unfortunately ignores the alpha channel (it sets the color to black instead), I need to undistort the (distorted) masks in addition to the standard PrepareDenseScene. Thank you for the hint on distortionParams in the `sfm file. I will see if I manage to use that for undistortion and if it helps to solve my issues.

@ALfuhrmann
Copy link

Hm. The sparse reconstruction is the step that generates the camera calibration.

But if you have an already previously calibrated camera, you can use the PrepareDenseScene node for rectifying the images, that's what it does.

@isolin
Copy link
Author

isolin commented Feb 8, 2021

No, I don't have a calibrated camera. But the issue is that dynamic stuff on the one hand and "static" text rendered in the video (displaying actual gps coordinates) perfectly fool the implicit camera calibration.

I figured out how to run the aliceVision binaries so I will just use the prepareDenseScene with a helper folder containing the masks. Hope it works.

@isolin
Copy link
Author

isolin commented Feb 8, 2021

Update: I was successful in undistorting my masks and setting -1 at the respective positions in the depth maps. I manually checked and yes the depth map is now correctly masked. However, the artifacts are still present in the texture and I have the feeling (can't verify) that they also increase noise in the mesh itself.

For the masked test which is always at the bottom, I can just crop the image, but I would like to get a correct pipeline so that similar errors do not appear for regions that can not be cropped like people or reflective surfaces in the middle of the image.

For illustration, here are the white artifacts repeating in patterns as the camera flies over the landscape. One can also see some border around. I assume it is caused by banding in the texturing node. So I wonder if anyone knows how to make masking work with texturing?

@fabiencastan, is there a chance to see it in the upcoming release planned for this month? It is already a very old #188 feature request. I am sure it would make a huge impact on the quality once the doors would open for any sort of manual or automated preprocessing to mask out troublemakers like moving objects, useless background stuff, highly reflective and glossy surfaces etc.

I love the concept of AliceVision! I think it does not need fancy nodes to do masking automatically #750. One can use plenty of other tools for that. In first row it needs a great and reliable core. And for masking, it's just about handling alpha properly all over the pipeline like the basis proposed in #715 plus Texturing 😄

artifacts1
artifacts2

@isolin
Copy link
Author

isolin commented Feb 8, 2021

It is definitely banding in the Texturing that produces the issues. Here another screenshot of the same area. Now I decreased Multi Band Downscale from the default 4 to 2 and increased the weight of high and mid-high frequencies. The result is much better, yet the borders of the mask are still visible, mainly on the dark green patch of dwarf pine (pinus mugo).

artifacts3

@stale
Copy link

stale bot commented Jun 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale for issues that becomes stale (no solution) label Jun 9, 2021
@natowi natowi removed the stale for issues that becomes stale (no solution) label Jun 10, 2021
@stale
Copy link

stale bot commented Oct 12, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale for issues that becomes stale (no solution) label Oct 12, 2021
@stale
Copy link

stale bot commented Apr 19, 2022

This issue is closed due to inactivity. Feel free to re-open if new information is available.

@stale stale bot closed this as completed Apr 19, 2022
@mscussiatto
Copy link

Hi @isolin , have you by any chance come across a solution for this, or are you still using this method?

I am segmenting objects using SAM and HED and would like to maybe back project these masks onto my already texturized mesh.

@isolin
Copy link
Author

isolin commented May 27, 2023

Nope, I didn't make it. I located the texturing code that I would need to edit in order to take masks into account, but I never found time for it.

@natowi
Copy link
Member

natowi commented May 29, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale for issues that becomes stale (no solution) type:question
Projects
None yet
Development

No branches or pull requests

4 participants