keri
(kerim khemraev)
November 17, 2021, 10:43pm
1
Hi,
When I add volume and change units from mm
to say m
I can see no difference on the ruler but in the same time the slice control widget’s spinbox changes units to meter. I suspect this is a bug?
Here is the code to create a volume:
nodeName = "MyNewVolume"
imageSize = [10, 10, 10]
imageOrigin = [10.0, 0.0, 0.0]
imageSpacing = [1, 1.0, 1.0]
scalars = vtk.vtkDoubleArray()
scalars.SetName("my_scalars")
for i in range(0, imageSize[0]*imageSize[1]*imageSize[2]):
v = scalars.InsertNextValue(i)
# Create an image volume
imageData = vtk.vtkImageData()
imageData.SetDimensions(imageSize)
imageData.GetPointData().SetScalars(scalars)
# Create volume node
volumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", nodeName)
volumeNode.SetOrigin(imageOrigin)
volumeNode.SetSpacing(imageSpacing)
volumeNode.SetAndObserveImageData(imageData)
volumeNode.CreateDefaultDisplayNodes()
volumeNode.CreateDefaultStorageNode()
Slicer 4.11.2
lassoan
(Andras Lasso)
November 18, 2021, 12:14am
2
Not all widgets are unit-aware. See list of widgets that require update in this issue:
opened 06:44PM - 11 Jul 20 UTC
type:bug
For numerical stability of various processing methods, it is important to avoid … very small and very large numbers.
By default, Slicer uses millimeter as unit, therefore for microscopy images the image spacing could be very small (for example, 0.00006mm) and derived values even smaller (volume of a voxel would be 0.000000000000216mm3). This could lead to display issues (hard to read the numbers, not enough space to display them) and numerical instabilities and loss of precision. The solution is to use a more appropriate unit, such as micrometer or tenth of a micrometer.
Slicer allows specifying what is the unit of length values of the scene and has unit-aware slider and spinbox widgets to correctly display them. However, the implementation is not fully complete and consistent. Remaining tasks:
- [ ] Use unit-aware widgets (or unit-aware formatting) whenever displaying numerical values with units. There are a number of places where “mm” unit is hardcoded and should be display should be replaced with unit-aware widgets.
- [ ] Transforms module display settings: I remember I had crashes with these widgets in Transform module’s display section and could not easily find the root cause, so just hardcoded mm, but we should give this another go. Examples include: view rulers (horizontal line at the bottom of views) and markups measurements (length of line and curves, surface area of closed curves).
- [x] Markups measurements
- [x] Slice offset slider
- [ ] Segment statistics
- [ ] Labelmap statistics
- [ ] View ruler (horizontal ruler displayed in slice and 3D view nodes)
- [ ] Models module, information section
- [ ] Importers should convert distance units. For example, when loading a DICOM file and the length unit is not mm, the voxel size must be scaled accordingly.
- [ ] Exporters should write distance units into files.
- [ ] CLI module interface should be made unit-aware.
- [ ] All transformable data in the scene must be rescaled when length unit is changed.
- [ ] All transformable data in the scene must be rescaled when a scene with a different unit is imported.
Until all these are implemented, a workaround is to enter values in a different unit (e.g., enter 0.06 "mm" instead of the real 0.06 micrometer), but don't change the unit in application settings. Then user would know that all units that Slicer displays in millimeters are actually in the other chosen unit (i.e., micrometer). See some more details and explanation here: https://discourse.slicer.org/t/distance-measurement-and-rendering-of-microscopy-images/791
It would be great if you could work on this.
1 Like
keri
(kerim khemraev)
November 18, 2021, 12:19am
3
Thank you, I will keep in mind