Open arsalanfiroozi opened 3 weeks ago
Hello, could you include the version info for SciPy/NumPy/Python?
You can get them with this:
import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info);
I looked into why this plot looks like this. When I plot a single 2D layer of this 3D array, I get the following result for mask:
plt.imshow(mask[50])
plt.colorbar()
plt.show()
And the following result for zoomed mask.
plt.imshow(zoomed_mask[50])
plt.colorbar()
plt.show()
Which look visually identical.
Looking at the arrays, mask has zeros where the sphere is.
>>> print(mask[50])
[[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]]
But zoomed_mask has values very close to zero.
>>> print(zoomed_mask[50])
[[-2.73008327e-64 4.48669571e-63 2.98858092e-63 ... 7.35583558e-62
4.81237224e-63 5.64220157e-63]
[ 3.47812810e-64 9.82065113e-63 1.14177549e-62 ... -5.28495731e-61
-5.63448647e-62 1.48921256e-62]
[-9.62627161e-63 1.21406027e-62 6.31602054e-62 ... -1.36521778e-60
-2.06049781e-61 1.28043091e-61]
...
[-6.97146241e-62 -1.37985552e-61 5.45084572e-61 ... -5.55510792e-60
-5.19043953e-61 -6.48359415e-62]
[-2.95606196e-62 -7.19974141e-62 -2.14201518e-61 ... -4.31188291e-61
3.37309667e-61 2.80366236e-61]
[-4.08125980e-63 -1.64422845e-62 -1.88761873e-62 ... 2.78968899e-61
6.02296151e-63 -1.62186346e-62]]
However, according to the documentation for matplotlib, voxels interprets non-zero values as filled values:
A 3D array of values, with truthy values indicating which voxels to fill
So this gives us a work-around, which is to avoid filling in near-zero values.
# Plot the original and zoomed masks in 3d
fig = plt.figure()
ax = fig.add_subplot(121, projection='3d')
ax.voxels(mask, edgecolor='k')
ax.set_title('Original Mask')
ax = fig.add_subplot(122, projection='3d')
ax.voxels(~np.isclose(zoomed_mask, 0), edgecolor='k')
ax.set_title('Zoomed Mask')
plt.show()
Describe your issue.
Hey, I am using scipy.ndimage.zoom for 3d images. Based on the input parameters, I might need to zoom or not. So, I expect the function to act as an identity function if the zoom factor is one. You can see the code and the output.![mask](https://github.com/scipy/scipy/assets/67230071/541ef52f-c1e3-453d-b34c-6397cd91d642)
Reproducing Code Example
Error message
SciPy/NumPy/Python version and system information