ResampleToImage filter output save as a mhd file

I have created a volumetric mesh using gmsh toolkit. It has an ellipsoid inside of a box. I have used two physical groups one is to hold the data for ellipsoid and the other group is to hold the whole 3D volumetric mesh using gmsh. I’m able to export this mesh as a .vtk file (i.e. as an unstructuredGrid) using the gmsh GUI.

Then I loaded it to the ParaView and applied ResampleToImage filter to this volumetric mesh in order to sample its point and cell data on to a uniform grid of points.

Now I want to write this output as a 3D image volume i.e. in .mhd format. I have tried to save it as a .mhd file (File->Save Data->Select Meta Image File Format and then save) using the ParaView, but unfortunately, the output file is always empty and only contains the header. Any possible reason for this ?

How can I save the vtkResampleToImage filter output as .mhd format ?

Hello,

Is the result of the ResampleToImage a valid grid with the data you expect in it ?

Once you save the mhd, you should have two files, a .mhd and a .zraw do you see both ?

For your first question the answer is yes, I just applied the clipping view for entire volumetric mesh after applying the ReampleToImage Filter as you can see the attached image below.

I have saved the output (i.e. after applying the ResampleToImage filter) as .mhd format, but unfortunately the file is empty. The saved location consists of two files namely .mhd and .zraw, but .zraw file is empty. Any reason or did I forget any steps before saving it as .mhd file ?

I herewith attached the generated .mhd file for your further reference.
resampled_img_mhd.zip (485 Bytes)

In the file that you shared, there is one scalar field, named MetaImage. ̶I̶t̶ ̶c̶o̶n̶t̶a̶i̶n̶s̶ ̶d̶o̶u̶b̶l̶e̶s̶,̶ ̶t̶h̶e̶ ̶f̶o̶u̶r̶ ̶f̶i̶r̶s̶t̶ ̶h̶a̶v̶e̶ ̶a̶ ̶r̶e̶a̶l̶l̶y̶ ̶s̶m̶a̶l̶l̶ ̶v̶a̶l̶u̶e̶ ̶(̶4̶.̶6̶6̶7̶2̶6̶e̶-̶3̶1̶0̶)̶ ̶a̶n̶d̶ ̶a̶l̶l̶ ̶t̶h̶e̶ ̶r̶e̶s̶t̶ ̶i̶s̶ ̶0̶.̶ (this is just garbage memory)
Can you try to save your data as a vti to see what happens ?

I just generated a .vti file and it consists of all the data that I need. See below. Here is the clipping view of that.

resampled_data_vti.zip (25.1 KB)

I see. I was able to reproduce the problem with your vti file.
This is due to an internal mechanism inside ParaView where some filters assume there is an active scalar array.
Fortunately, there is a workaround. You can simply apply a Calculator on your data set:

  • In the input field, enter the name of your scalar array: CellEntityIds in your example
  • You can also change the name of the output array if you want
  • Apply

Now, if you save the result of the Calculator as a mhd file, it should contains the right scalar field.
res.zip (17.8 KB)

1 Like

Thank you very much. It is perfectly working now. Thanks again.

One more question.

Is that possible to change the output mhd file’s foreground colour to white and background to zero before saving it as a .mhd file?
I’m asking this because the generated image volume consists of opposite way where foreground or the ellipsoid is in black colour. And the slices which does not consists the ellipsoid region is appeared as black (see the first image).

See the attached two image slices below (I here used a python code to visualize the generated mhd file).

First image represents the 10th slice and the last one is the 50th slice.

slice_10 slice_50

I just check the pixel values. I have resolved it.