# How to change number of points and cells in a surface model?

Hello Dear Developers and Users

I have several surface models. Specifications of one of these surface models are:

Surface Area: 3492.57 mm^2
Volume: 10828.02 mm^3
Number of Points: 1029
Number of Cells: 336

I want to be able to change these specifications especially Number of Points and Number of Cells. How can I do that?

For example, I want to change these specifications in all my surface models to the following:
Number of Points: 1200
Number of Cells: 400

What modules should I use in Slicer or SlicerSALT?

In summary, My ultimate goal is to same number of points and number of cells in surface models. Please guide me as soon as possible.

Thanks a lot,
Shahrokh

If no of cells is,same as no of triangles, you can use reduce option in meshmixer, a standalone softwate.

The easiest way to achieve matching number of points is to add duplicate points to all models that have less points than the others. Would that be acceptable? Why do you need exact match of number of points?

Do you need correspondence between mesh points (do you expect 123th point in mesh A to be at the same anatomical location as point 123th in mesh B)? If yes, then what you need is a spatial correspondence between meshes: transformation that transforms points of one mesh to the other. This transformation is computed by spatial registration algorithms. Once you have transform between mesh A to B, you can apply that to points of mesh A and get a mesh that has the same shape as mesh B, but contains exactly the same number of points and cells, in the same order, as mesh A.

There are several ways of registering meshes in Slicer. For example, you can import your meshes to Segmentation node and use the methods described in this post: align two segments to each other .

1 Like

You can try to use the Decimation option in the Surface Toolbox module, however there you cannot exactly specify the number of triangles, only a reduction factor. It might still be possible to make them match.

What exactly you want to achieve with having exactly the same number of cells and points?

Hello
Dear Anil, Andras and Csaba

My tomographic images (MRI) are nifti format. Before, I convert region segmented (using itk-snap) to binary images.
I convert these binary images to the model by â€śGrayscale Model Makerâ€ť module using Threshold equal to 1. For example, I have given the specifications of one of theses models in the my first message.

Unfortunately, I can not work with SlicerIGT and If I did not get it wrong, as Andras pointed out, I used â€śSurface Registrationâ€ť in â€śCMF Registrationâ€ťmodule to register these models .
In this module, I select â€śSurface Registrationâ€ť for â€śType of Registrationâ€ť.
I select one of the models as the Fixed Model and the other model as Moving Model.
The outputs of this module are the â€śTransformâ€ť matrix and the transmitted model.
If I did not get it wrong, how can I use this matrix to integrate the number of points and cells between models? In other words, what Slicer module should I use for this purpose.

Shahrokh

Please try doing the segmentation using Slicerâ€™s Segment Editor module. It is a relatively new, much improved segmentation module that I think you will find at least as good as ITK-Snap.

Then you can register the segmentations using the Segment Registration module, for which you need to install the Segment Registration extension from Extension Manager.

Let us know how it goes.

If you already have a segmentation then you can load it into Slicer as a labelmap volume node and import that into a segmentation node (using Segmentations module).

After registration is completed, apply and harden the transform to the first model to get another model that has the same number of points and cells as the first model, but the shape of the second model.

Hello
Dear Andras and Csaba

Sorry about that I can not to do it.
At firstly, I mentioned that I did the steps that Andras pointed out, but unfortunately I did not succeed.
I will explain all the processes that I do.

At it, I add sample1_C1_group04.nii and sample1_C1_group05.nii. For doing it, I choose these files and tick â€śLabelMapâ€ťoption in the window of â€śAdd data into the sceneâ€ť. I think that I do these step as mentioned Andras.

Process #2: â€śModel Makerâ€ť module
In â€śModel Makerâ€ť, I do the following steps:
1- In Input Volume, I select my first LabelMapVolume with the name ample1_C1_group04
2- I create new ModelHierarchy
3- I named it to ModelS1C1G4
4- I set â€śStart Labelâ€ť and â€śEnd Labelâ€ť to 1
5- I set â€śSmoothâ€ť to 0 and then â€śApplyâ€ť.
6- I do steps above for my second LabelMapVolume with the name ample1_C1_group05
After doing it, I have two models with the names of ModelS1C1G4 and ModelS1C1G5 with the following specifications:
ModelS1C1G4:
Surface Area: 3816.23 mm^2
Volume: 133300.13 mm^3
Number of Points: 1479
Number of Cells: 541
ModelS1C1G5:
Surface Area: 2940.01 mm^2
Volume: 9805.02 mm^3
Number of Points: 1168
Number of Cells: 449
After doing, I can clearly see these two models, seperately.
Note: I want that â€śNumber of Pointsâ€ť and â€śNumber of Cellsâ€ť of ModelS1C1G5 are same as ModelS1C1G4.

Process #3: â€śModel Registrationâ€ť module
At it, as mentioned Andras it, I want to calculate transform matrix; so I do the following steps:
1- In â€śInput fixed (dense) modelâ€ť, I select ModelS1C1G4.
2- In â€śInput moving (sparse) modelâ€ť, I select ModelS1C1G5.
3- I create new LinearTransorm with the name of â€śLinearTransform_3â€ť
4- In part of â€śAdvancedâ€ť, I select â€śRigidâ€ť for â€śTransform typeâ€ť.
5- I click â€śApplyâ€ť.
6- After doing it, I get 1.18665655941 in â€śMean distance after registrationâ€ť.

Process #4: â€śTransformsâ€ť module;
1- I select â€śLinearTransform_3â€ť in â€śActive Transformâ€ť
2- In the part of â€śApply transformâ€ť, firstly I select ModelS1C1G4 and apply â€śLinearTransform_3â€ť to it.
3- In â€śDataâ€ť module, I select ModelS1C1G4 and then right click and select â€śHarden Transformâ€ť

After doing these steps, I expect to be equal to â€śNumber of Pointsâ€ť and â€śNumber of Cellsâ€ť of ModelS1C1G5 with ModelS1C1G4; but unfortunately, that did not happen.

Iâ€™m really confused. Please guide me to solve it.

Thanks a lot;
Shahrokh.

The main point is that when you apply a transform to a model, number of points or cells of that model does not change (compared to the original, non-transformed model).

I would recommend to not use Model Maker (unnecessary, Segmentations take care of conversions between various representations) and use Segment Registration for alignment (since it can do non-linear warping to better match the meshes).

Thanks a lot Andras.

Also,Csaba had also mentioned to use â€śSegment Registrationâ€ť module in his message; but unfortunately, I can not find â€śSegment Registrationâ€ť module; even I search â€śSegment Registrationâ€ť in â€śExtension Managerâ€ť on Slicer. It was not.
I work with Slicer version 4.6.2 r25516.
Should I install this module (Segment Registration)?
OR
is it installed by default on Slicer? If Ok, what version is there?

Thanks a lot.
Shahrokh

Wow, Slicer 4.6 - that was released two years ago! We are making huge improvements to Slicer week by week, so a two-year-old version is completely outdated. You should always use at least the latest stable version(currently Slicer-4.8), and if you donâ€™t find something there or something is not working as expected then try a recent nightly (not older than 1-2 weeks).

Dear Andras and Csaba,

Really excuse me, I download Slicer-4.9.0-2018-01-10-linux-amd64 and install â€śSegment Registrationâ€ť module. I really hope that my problems will be solved.
Thanks thanks thanks
Shahrokh

Excellent, thanks for the update! I also hope it will work for your use case. Let us know if not.

Hello
Dear Andras and Csaba

As mentioned you, at now, I work with Slicer-4.8.1-linux-amd64 and install â€śSegment Registrationâ€ť module. Unfortunately I can not same â€śNumber of Pointsâ€ť and â€śNumber of Cellsâ€ť between two models.

This may be better to point out my purpose. Please look at my post with titled â€śShape analysis between non-similar objects?â€ť in â€ś3D Slicer Forumâ€ť.
Briefly, suppose I have 5 groups with names A, B, C, D and E and in each group there are 8 meat samples (with size 2x2x2 cm^3 each sample, approximately). Each group was subjected to different laboratory procedures (physicochemical methods) and these procedures had a significant effect on the surface of the samples that it is recognizable by any observer.
I get MRI images from these samples separately. I put meat samples from each group on the flat surface (one chess score sheet) and after MRI acquisition, I cropped sample slice images and convert to binary segmented images using softwares such as itksnap, Seg3D and Slicer. Now I want to 3D surface analysis the effects of these procedures on the surface of these meat samples using SlicerSALT (SPHARM). At that time, Beatriz guide me that I have to check if correspondence is good across all meat samples. (I thank Beatriz for all patiently guidance). Unfortunately, I did not understand how I can match meat samples.

At now, I want to same number of points and cells between two extracted models from MRI samples.

As mentioned Andras and Csaba, I download Slicer-4.8.1-linux-amd64 and install â€śSegment Registrationâ€ť module.

For example, I do the following steps for two samples (binary segmented images):

#1: Load data as LabelMap (WITH tick â€śLabelMapâ€ť) :

#2: Load data as volume (WITHOUT tick â€śLabelMapâ€ť):
Rename sample1_C1_group04.nii to Volume_sample1_C1_group04
Rename sample1_C1_group05.nii to Volume_sample1_C1_group05

#3: Segmentations module:
In â€śActive segmentationâ€ť â†’ Create new Segmentation with the name MySegmentation
In â€śExport/import models and labelmapsâ€ť â†’ in â€śOperationâ€ť, choose â€śImportâ€ť and in â€śInput typeâ€ťchoose â€śLabelmapâ€ť and select sample1_C1_group04 and in â€śInput nodeâ€ť and finally click on â€śImportâ€ť and again select sample1_C1_group05 in â€śInput nodeâ€ť and finally click on â€śImportâ€ť

#4: â€śDataâ€ť module:
In â€śSubject hierarchyâ€ť tab â†’ right click on â€śMySegmentationâ€ť and click on â€śExport visible segments to modelsâ€ť

#5: â€śSegment Registrationâ€ť module:
In â€śFixed imageâ€ť select Volume_sample1_C1_group04
In â€śFixed segmentationâ€ť select MySegmentation
In â€śFixed segmentâ€ť select sample1_C1_group04
In â€śMoving imageâ€ť select Volume_sample1_C1_group05
In â€śMoving segmentationâ€ť select MySegmentation
In â€śMoving segmentâ€ť select sample1_C1_group05

in â€śResultsâ€ť and â€śApplied registration on moving study, select â€śDeformableâ€ť defult and I can not changed it.
Click on â€śPerform registrationâ€ť
After doing it, the options of â€śApplied registration on moving studyâ€ť in â€śResultsâ€ť could be changed.
At this time, I get messages in â€śLog messagesâ€ť window; as following:

Performing registration workflow
Cropping moving volume
Pre-aligning segmentations
Fixed segment bounds: [16.945327758789062, 59.18786621093749, -94.15547943115234, -79.90632629394531, -141.16146850585938, -102.09896850585938]
Moving segment bounds: [158.5375518798828, 200.83857727050778, -95.2843017578125, -77.4457015991211, -124.57463836669922, -100.2640151977539]
Moving to fixed segment translation: [-141.62146759033203, -0.6659011840820312, -9.210891723632812]
Resampling fixed volume
Creating contour labelmaps
Performing distance based registration
Setting up result visualization
Performing registration workflow
Cropping moving volume
Pre-aligning segmentations
Fixed segment bounds: [16.945327758789062, 59.18786621093749, -94.15547943115234, -79.90632629394531, -141.16146850585938, -102.09896850585938]
Moving segment bounds: [158.5375518798828, 200.83857727050778, -95.2843017578125, -77.4457015991211, -124.57463836669922, -100.2640151977539]
Moving to fixed segment translation: [-141.62146759033203, -0.6659011840820312, -9.210891723632812]
Warning: In /home/kitware/Dashboards/Package/Slicer-481/Libs/MRML/Core/vtkMRMLTransformNode.cxx, line 1515
vtkMRMLLinearTransformNode (0x6932680): vtkMRMLTransformNode::SetAndObserveMatrixTransformToParent method is deprecated. Use vtkMRMLTransformNode::SetMatrixTransformToParent instead

_DeserializeImageGeometry: Failed to de-serialize geometry string _

ApplyTransformOnReferenceImageGeometry: Failed to get reference image geometry

Resampling fixed volume
_Found CommandLine Module, target is /home/sn/Slicer-4.8.1-linux-amd64/lib/Slicer-4.8/cli-modules/ResampleScalarVolume _
_ModuleType: CommandLineModule _
_Resample Scalar Volume command line: _

_/home/sn/Slicer-4.8.1-linux-amd64/lib/Slicer-4.8/cli-modules/ResampleScalarVolume --spacing 1,1,1 --interpolation lanczos /tmp/Slicer/CCJDG_vtkMRMLScalarVolumeNodeB.nrrd /tmp/Slicer/CCJDG_vtkMRMLScalarVolumeNodeE.nrrd _
_ _
Resample Scalar Volume completed without errors
_ _
Loaded volume from file: /tmp/Slicer/CCJDG_vtkMRMLScalarVolumeNodeE.nrrd. Dimensions: 47x20x44. Number of components: 1. Pixel type: unsigned short.

Creating contour labelmaps
Performing distance based registration
Traceback (most recent call last):
_ File â€ś/home/sn/.config/NA-MIC/Extensions-26813/SlicerProstate/lib/Slicer-4.8/qt-scripted-modules/DistanceMapBasedRegistration.pyâ€ť, line 249, in onApplyButton_
_ logic.run(self.parameterNode)_
_ File â€ś/home/sn/.config/NA-MIC/Extensions-26813/SlicerProstate/lib/Slicer-4.8/qt-scripted-modules/DistanceMapBasedRegistration.pyâ€ť, line 356, in run_
_ (bbMin,bbMax) = self.getBoundingBox(fixedLabelNodeID, movingLabelNodeID)_
_ File â€ś/home/sn/.config/NA-MIC/Extensions-26813/SlicerProstate/lib/Slicer-4.8/qt-scripted-modules/DistanceMapBasedRegistration.pyâ€ť, line 501, in getBoundingBox_
_ unionLabelImage = (cast.Execute(fixedLabelImage) + cast.Execute(movingLabelImage)) > 0_
_ File â€ś/home/sn/Slicer-4.8.1-linux-amd64/lib/Python/lib/python2.7/site-packages/SimpleITK/SimpleITK.pyâ€ť, line 4254, in add_
_ return Add( self, other )_
_ File â€ś/home/sn/Slicer-4.8.1-linux-amd64/lib/Python/lib/python2.7/site-packages/SimpleITK/SimpleITK.pyâ€ť, line 11002, in Add_
RuntimeError: Exception thrown in SimpleITK Add: /home/kitware/Dashboards/Package/Slicer-481-package/ITKv4/Modules/Core/Common/include/itkImageToImageFilter.hxx:241:
itk::ERROR: AddImageFilter(0x6675f10): Inputs do not occupy the same physical space! _
InputImage Origin: [1.2437664e+02, 9.9558647e+01, -1.4970284e+02], InputImage_1 Origin: [-1.7810860e+01, 9.4871147e+01, -1.3251534e+02]
_ Tolerance: 1.5625000e-06

Setting up result visualization

#5: â€śDataâ€ť module:
In â€śTransform hierarchyâ€ť and in â€śDeformable Transformâ€ť list, right click on â€śVolume_sample1_C1_group05â€ť and select â€śHarden transformâ€ť

#6: â€śModelsâ€ť module:
Unfortunately, I see that â€śNumber of Pointsâ€ť and â€śNumber of Cellsâ€ť are NOT the same. Why?!

Shahrokh

Iâ€™m not familiar with the shape analysis methods youâ€™re trying to use, but ensuring an exact match between number of vertices seems like a very unrealistic goal.

Surface models are mostly used for 3D visualization, and analysis is almost always done on labelmaps, so such limitations have not been needed. But even if you achieve the same number of vertices somehow, itâ€™s very hard to ensure that if you set a correspndence between each pair of vertex, they will really correspond spatially. As the shape and size of triangles is not a priority to keep consistent, there will be a â€śdriftâ€ť eventually when you want to set up correspondence.
You can use regularization methods to keep triangles the same size and shape, but then the smallest difference in your samples will result in a difference in number of vertices.

Have you considered using labelmaps or even other representations such as simplex meshes?

Hello
Dear Csaba and Andras

Thanks a lot for your replies. According with your guidance, I want to use labelmap volumes. I have some questions about it.
1- Can I do comparison the surfaces of labelmaps between several groups?
2- Can I create a average labmap volume from existing labmaps in a group?
3- Can I compare between surface features of MRI (meat) samples such as shrinkage?
4- Can I compute distance between two labelmaps just like as â€śModelToModelDistanceâ€ť module?

The point I should mention is that MRI images taken from meat samples are in following conditions:
a- The dimensions of the meat samples are not exactly the same. Their volume is almost equal to 8.0 cm^3 but certainly their dimensions are not same.
b- The orientation of meat fibers is not the same.
However, I think as two signals can be different in the frequency spectra, two surfaces can also be different in features such as spherical harmonics. In other words, I imagine MRI meat samples like as 3D signals that I want to extract fundamental frequencies and compare between them. How can I do it?

Also you mention to use simplex mesh. Please guide me to understand difference between simplex mesh and mesh available in 3DSlicer. At it, please give me more guidance.

Thanks a lot;
Shahrokh

Segment statistics module provides surface area measurement for each individual segment.

You can, for example by aligning segments to each other, export them to labelmap, computing distance map (using Simple Filters module), average distance maps, and threshold it at 0.

Segment statistics gives you segment volume, so you can easily compute shrinkage.

Yes, I think difference of distance maps should provide that. Or, apply model to model distance on the segment exported to a model node.

Check out SlicerSalt shape analysis toolbox. You may also experiment with simple PCA-based modeling, but for that you need to wrap ITK filters in a Slicer CLI module, as I donâ€™t seem to find any module that wraps ITKâ€™s PCA filters (https://itk.org/Doxygen/html/classitk_1_1ImagePCAShapeModelEstimator.html and others).

You can also use the Segment Comparison module from the SlicerRT extension.
Of course it only makes sense after you established spatial correspondence, for example using the Segment Registration extension.

Simplex mesh is a very special class of mesh that has been developed at Inria. It is a hexagon-based mesh that is designed to be regular. As far as I know there is no support for it in Slicer at this point, and it never became a standard representation, but if you like its features then it may be of interest. Keep in mind that adding its support in Slicer might be a huge project. Hereâ€™s a paper about it.