# Loading vector fields (.vf)

**URL:** <https://discourse.slicer.org/t/loading-vector-fields-vf/15660>\
**Category:** Support\
**Created:** [January 25, 2021, 6:10pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660 "2021-01-25T18:10:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![marianaslicer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/marianaslicer/32/8555_2.png) [@marianaslicer](https://discourse.slicer.org/u/marianaslicer)\
**Post date:** [January 25, 2021, 6:10pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/1 "2021-01-25T18:10:44Z")

</div>

Hello everyone,

Is it possible to load vector fields with .vf extension? I tried to load them in the preview release 3D Slicer version but I couldn’t do it.  
I would appreciate any help.  
Thank you.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 25, 2021, 8:04pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/2 "2021-01-25T20:04:11Z")

</div>

What software generated this file?

Can you save it as a NRRD volume file or ITK HDF5 transform file instead? (these are the formats Slicer can read displacement fields from)

If you cannot save your vector field in any of these formats then you can you have a few other options:

- load the .vf file as a numpy array with some Python package that can read such files, then use [slicer.util.updateVolumeFromArray](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.updateVolumeFromArray) to get it into a volume node (which can then be saved as a .nrrd file)
- use RawImageGuess extension to generate a NRRD file header (.nhdr file) that Slicer can use to load the volume

---

<div class="post-metadata">

**Author:** ![marianaslicer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/marianaslicer/32/8555_2.png) [@marianaslicer](https://discourse.slicer.org/u/marianaslicer)\
**Post date:** [January 26, 2021, 9:46am UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/3 "2021-01-26T09:46:32Z")

</div>

Hi Andras, thank you for your response.

I was trying to use the online available dataset [popi-model\_original\_page - Rayonnement, Images, Oncologie (insa-lyon.fr)](https://www.creatis.insa-lyon.fr/rio/popi-model_original_page), including CT images, masks and vector fields. I can load them into VV software, but I’m afraid that I cannot save them as a NRRD volume file or another format type. So, I will try to follow your suggestion. Thank you.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 29, 2021, 6:18am UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/4 "2021-01-29T06:18:54Z")

</div>

The website describes the format of the data. You can use that information in [RawImageGuess](https://github.com/acetylsalicyl/SlicerRawImageGuess) extension.

---

<div class="post-metadata">

**Author:** ![grupesh](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@grupesh](https://discourse.slicer.org/u/grupesh)\
**Post date:** [June 20, 2022, 4:14pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/5 "2022-06-20T16:14:15Z")

</div>

@marianaslicer Were you able to use RawImageGuess module to load .vf files? If yes, can you please share that? I’m trying to use these .vf data in matlab/python and I don’t see a way to export them from VV software.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 21, 2022, 1:57am UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/6 "2022-06-21T01:57:39Z")

</div>

Writing a small Python script to read these files could be a nice little project for the [upcoming Slicer Project Week](https://projectweek.na-mic.org/PW37_2022_Virtual/). You can still sign up, it is virtual and participation is free of charge. You just need to describe your project in a few sentences and upload it to the project week website; present your project it in 1 minute on the first day, work with experts during the week, and present what you accomplished in 1 minute on the last day.

---

<div class="post-metadata">

**Author:** ![grupesh](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@grupesh](https://discourse.slicer.org/u/grupesh)\
**Post date:** [June 21, 2022, 6:19pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/7 "2022-06-21T18:19:01Z")

</div>

@lassoan thanks for your suggestion. I was able to write a python script to read these .vf files and convert them to np arrays / .mhd (which works with VV, Slicer)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 21, 2022, 6:39pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/8 "2022-06-21T18:39:53Z")

</div>

Great! Would you mind sharing the script so that others can use it, too?

If you want to read these files conveniently (just by drag-and-dropping the file into Slicer) then you can put your script in the `load` method of a file reader plugin. See example [here](https://github.com/Slicer/Slicer/blob/master/Applications/SlicerApp/Testing/Python/SlicerScriptedFileReaderWriterTest.py). I would be happy to help you with this if you are OK to make the script public.

---

<div class="post-metadata">

**Author:** ![grupesh](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@grupesh](https://discourse.slicer.org/u/grupesh)\
**Post date:** [June 22, 2022, 2:53pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/9 "2022-06-22T14:53:38Z")

</div>

Sure, I would be happy to share the script / add it in file reader plugin. I’m git cloning the slicer repo and adding the code. Not sure on how to test it. Happy to work with you on that.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 25, 2022, 3:05pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/10 "2022-06-25T15:05:43Z")

</div>

No need to clone the Slicer repository, as you just add a Python scripted module in an extension. [This page](https://slicer.readthedocs.io/en/latest/developer_guide/api.html#tutorials) should help you getting started and you can ask us here if you have any questions.

---

<div class="post-metadata">

**Author:** ![cslzq1998](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cslzq1998/32/16318_2.png) [@cslzq1998](https://discourse.slicer.org/u/cslzq1998)\
**Post date:** [August 16, 2022, 12:24pm UTC](https://discourse.slicer.org/t/loading-vector-fields-vf/15660/11 "2022-08-16T12:24:02Z")

</div>

Would you please share the script here?I don’t know how to convert it to a format like numpy array or medical image
