def dcm_to_volume(dir_path): itk_image = itk.imread(dir_path) vtk_image = itk.vtk_image_from_image(itk_image) volume_state = to_volume_state(vtk_image) return volume_state
empty_da = itk.xarray_from_image(empty_image) empty_image_round = itk.image_from_xarray(empty_da) except ImportError: print("xarray not imported. Skipping xarray conversion tests") pass # vtk conversion try: import vtk print("Testing vtk conversion") print("Testing vtk conversion") image = itk.image_from_array(np.random.rand(2, 3, 4)) vtk_image = itk.vtk_image_from_image(image) image_round = itk.image_from_vtk_image(vtk_image) assert np.array_equal(itk.origin(image), itk.origin(image_round)) assert np.array_equal(itk.spacing(image), itk.spacing(image_round)) assert np.array_equal(itk.size(image), itk.size(image_round)) assert np.array_equal(itk.array_view_from_image(image), itk.array_view_from_image(image_round)) image = itk.image_from_array(np.random.rand(5, 4, 2).astype(np.float32), is_vector=True) vtk_image = itk.vtk_image_from_image(image) image_round = itk.image_from_vtk_image(vtk_image) assert np.array_equal(itk.origin(image), itk.origin(image_round)) assert np.array_equal(itk.spacing(image), itk.spacing(image_round)) assert np.array_equal(itk.size(image), itk.size(image_round)) assert np.array_equal(itk.array_view_from_image(image),
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import sys import itk import argparse from distutils.version import StrictVersion if StrictVersion(itk.Version.GetITKVersion()) < StrictVersion("5.2.0"): print("ITK 5.2.0 is required.") sys.exit(1) parser = argparse.ArgumentParser( description="Convert An RBG itk Image to vtk Image Data.") parser.add_argument("input_image") args = parser.parse_args() inputImage = itk.imread(args.input_image) vtkImage = itk.vtk_image_from_image(inputImage) print(vtkImage)