# vtkResampleToImage filter output save as a mhd file

**URL:** https://discourse.vtk.org/t/vtkresampletoimage-filter-output-save-as-a-mhd-file/4179
**Category:** Support
**Created:** [September 9, 2020, 11:15am UTC](https://discourse.vtk.org/t/vtkresampletoimage-filter-output-save-as-a-mhd-file/4179 "2020-09-09T11:15:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![isuruwi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/i/c0e974/32.png) [@isuruwi](https://discourse.vtk.org/u/isuruwi)
#### Post date: [September 9, 2020, 11:15am UTC](https://discourse.vtk.org/t/vtkresampletoimage-filter-output-save-as-a-mhd-file/4179/1 "2020-09-09T11:15:22Z")

</div>

I have created an unstructuredGrid and passed it into vtkResampleToImage filter 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 it as below code, but it generated an empty file with only the header.

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

```
vtkSmartPointer<vtkUnstructuredGridReader> reader =
        vtkSmartPointer<vtkUnstructuredGridReader>::New();
reader->SetFileName(ref_volumetric_mesh_path.c_str());
reader->ReadAllScalarsOn();
reader->SetReadAllScalars(true);
reader->Update();

vtkSmartPointer<vtkResampleToImage> filter = vtkSmartPointer<vtkResampleToImage>::New();
filter->SetInputDataObject(reader->GetOutput());
filter->SetInputConnection(reader->GetOutputPort());
filter->SetSamplingDimensions(60, 60, 100);
filter->Update();

vtkSmartPointer<vtkMetaImageWriter> writer = vtkSmartPointer<vtkMetaImageWriter>::New();
writer->SetFileName(ref_volumetric_mesh_voxelized_path.c_str());
writer->SetInputData(filter->GetOutput());
writer->Write();
```
