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

Different phase fraction on edges of blobs output #981

Open
amirDahari1 opened this issue Aug 1, 2024 · 7 comments · May be fixed by #991
Open

Different phase fraction on edges of blobs output #981

amirDahari1 opened this issue Aug 1, 2024 · 7 comments · May be fixed by #991

Comments

@amirDahari1
Copy link
Contributor

amirDahari1 commented Aug 1, 2024

On the edges of blobs output, there is a higher phase fraction then the inside of the output.

Here you can see the phase fraction for every slice along the first dimension in a 500x500x500 blobs output with phase fraction 0.1:

porespy_issue

@amirDahari1
Copy link
Contributor Author

amirDahari1 commented Oct 14, 2024

Not sure why this happens, probably the default 'reflect' mode of the scipy gaussian_filter, but a simple solution is creating something slightly larger and then crop the edges.

@jgostick
Copy link
Member

I have been meaning to address this bug, but just always too busy. The guassian blur function that is used has a mode argument which controls how the edges are handled. This should be a pretty simple thing to fix just by specifying either reflect or mirror. Interestingly, there is also the wrap mode...I wonder if that would allow for periodic boundaries?

@jgostick jgostick linked a pull request Oct 15, 2024 that will close this issue
@jgostick
Copy link
Member

I played with this and even created a PR, but my solution did not work. Using wrap solves the problem and has the added benefit of making a periodic image, which is quite handy. However, I am not sure why mirror and or reflect create this problem. In my understanding, both reflect and mirror should ensure the convolution does not suffer edge effects since the interior values are reflected outward, so the phase fraction at the edges should be representative. We are not doing anything fancy in the code, it's just gaussian_filter followed by any_to_uniform, followed by a threshold.

@jgostick
Copy link
Member

I spent a bit of time on this and reached the following conclusions:

  • Something is happening during the gaussian_blur which seems like a bug (maybe?). All of the edge modes, except 'wrap' result in the edge effects noted above. I am sure that reflect and mirror should not cause this.
  • When looking at the density distribution of the blurred image along the x-axis (i.e. summing up all the values for a given x and looking at the yz plane), there is no noticeable edge effect, but when I take a threshold THEN the edge effect appears. This seems to tell me that there is a minor bias in the edge values which is only noticeable once the values are booleaned.

@amirDahari1
Copy link
Contributor Author

why not use 'wrap'?

@jgostick
Copy link
Member

I was thinking that making the image periodic would not always be desired (though tbh I would prefer it). Also, it just bothers me that it's happening so I want to know why and how to fix it.

@amirDahari1
Copy link
Contributor Author

I think the answer is that the mirror and reflect modes make the edges have less variation in every square/cube, because the same numbers are used. This causes less smoothing by the gaussian filter because the filter is applied to less numbers and so the result is higher variation in the edges.

np.std(im[:1])
0.013613445803553578
np.std(im[20:21])
0.010896353309892862

This higher variation makes many of these pixels larger after all_to_uniform.

I think the solution is making a slightly bigger volume and then crop the edges affected by the mirror/reflect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants