Extract voxel information
-
wrote on 25 Mar 2020, 17:22 last edited by
Hi all
I need a way to export the voxel information to matlab, so I can mask out regions depending upon tissue type as part of my analysis. Specifically, I am looking at E field in the Duke model, but want to change the field in my plots in the bone to nan, to mask it out.
I think it should be possible to access the voxel information and do things with it in sim4life, and would appreciate a pointer int he right direction.
thanks
Will
-
wrote on 27 Mar 2020, 10:25 last edited by
You can use the Mask Filter in Field Data Tools to mask an extracted field by Material, before exporting to Matlab.
So for example, you can specify a value (in your case NaN) to replace all the voxels which are currently assigned with Bone.
If you use the scripter, it will look something like this, with entities being defined as everything except the Bone material in your model you want to mask out:
# Adding a new FieldMaskingFilter inputs = [convert_to_node_data_filter.Outputs["EM E(x,y,z,f0)"]] field_masking_filter = analysis.core.FieldMaskingFilter(inputs=inputs) field_masking_filter.SetAllMaterials(False) field_masking_filter.SetEntities(entities) field_masking_filter.UpdateAttributes() document.AllAlgorithms.Add(field_masking_filter)
There's more info in the html manual here:
Data Analysis & Postprocessing > Field Data Tools > Mask Filter -
wrote on 28 Mar 2020, 12:26 last edited by
This may also be more useful -
https://forum.zmt.swiss/topic/103/mask-filter-from-python-how-to-exclude-the-background-for-example -
wrote on 28 Mar 2020, 14:48 last edited by
Brilliant, exactly what I needed! Thanks so much.
-
wrote on 29 Mar 2020, 18:32 last edited by
I have implemented the filter to the data, but it does not get applied to the matlab export. I had the matlab export use the sensor output as an input previously, not sure how to make the input the output of the filter as all the things I have tried so far have not worked...
#make the mask
field_masking_filter = analysis.core.FieldMaskingFilter(inputs=inputs)
field_masking_filter.SetAllMaterials(False)
field_masking_filter.SetEntities(wanted_entities)
field_masking_filter.UpdateAttributes()
document.AllAlgorithms.Add(field_masking_filter)outname = dirout+'\\'+sim.Name+'_masked.mat' outname.replace(" ","") outname = ''.join(outname.split()) # Adding a new MatlabExporter but after the mask has been applied inputs = [field_masking_filter.GetOutput] matlab_exporter = analysis.exporters.MatlabExporter(inputs=inputs) matlab_exporter.ExportTo(outname) matlab_exporter.UpdateAttributes() document.AllAlgorithms.Add(matlab_exporter) matlab_exporter.Update()
-
wrote on 29 Mar 2020, 18:39 last edited by
I figured it out, made it in the gui and used to python to see what the syntax had to be
inputs = [field_masking_filter.Outputs["EM E(x,y,z,f0)"]]