{"id":9838,"library":"itk-core","title":"ITK (Insight Toolkit) Core","description":"ITK is an open-source, cross-platform toolkit for N-dimensional scientific image processing, segmentation, and registration in a spatially-oriented architecture. The `itk-core` package provides the fundamental Python bindings for ITK's C++ core functionalities. It is currently in a 5.4.x maintenance release cycle (5.4.5) with active development on the major 6.0 release.","status":"active","version":"5.4.5","language":"python","source_language":"en","source_url":"https://github.com/InsightSoftwareConsortium/ITK","tags":["image-processing","medical-imaging","n-dimensional","scientific-computing","computer-vision","signal-processing"],"install":[{"cmd":"pip install itk-core","lang":"bash","label":"Install core ITK Python bindings"}],"dependencies":[],"imports":[{"note":"Even when installing 'itk-core', the Python module is exposed under the 'itk' namespace.","wrong":"import itk_core","symbol":"itk","correct":"import itk"},{"note":"Most ITK classes are directly accessible via the top-level 'itk' namespace; avoid trying to guess submodules.","wrong":"from itk.io import ImageFileReader","symbol":"ImageFileReader","correct":"import itk\nreader = itk.ImageFileReader[itk.Image[itk.F, 3]].New()"}],"quickstart":{"code":"import itk\nimport numpy as np\nimport os\n\n# --- Setup: Create a dummy image if 'input.mha' doesn't exist ---\ninput_file = \"input.mha\"\noutput_file = \"output_smoothed.mha\"\n\nif not os.path.exists(input_file):\n    print(f\"{input_file} not found, creating a dummy 3D image for demonstration.\")\n    array_image = np.zeros((64, 64, 64), dtype=np.float32)\n    # Add a simple cube to the image\n    array_image[10:50, 10:50, 10:50] = 100.0\n    dummy_image = itk.image_from_array(array_image)\n    # Set metadata (origin, spacing) which is important for ITK images\n    dummy_image.SetSpacing([1.0, 1.0, 1.0])\n    dummy_image.SetOrigin([0.0, 0.0, 0.0])\n    itk.imwrite(dummy_image, input_file)\n    print(f\"Created {input_file}\")\n\n# --- Core ITK Usage: Read, Process, Write ---\n\n# 1. Define the image type (e.g., 3D float image)\nImageType = itk.Image[itk.F, 3] # itk.F for float, 3 for 3 dimensions\n\n# 2. Read an image\nprint(f\"Reading image from {input_file}...\")\nimage = itk.imread(input_file, ImageType)\nprint(f\"Original image size: {image.GetLargestPossibleRegion().GetSize()}\")\n\n# 3. Apply a filter (e.g., Gaussian smoothing)\nprint(\"Applying Gaussian filter...\")\ngaussian_filter = itk.GaussianImageFilter[ImageType, ImageType].New()\ngaussian_filter.SetInput(image)\ngaussian_filter.SetSigma(2.0) # Set the standard deviation for the Gaussian kernel\ngaussian_filter.Update() # Execute the filter\nsmoothed_image = gaussian_filter.GetOutput()\n\n# 4. Write the processed image\nprint(f\"Writing smoothed image to {output_file}...\")\nitk.imwrite(smoothed_image, output_file)\nprint(f\"Smoothed image size: {smoothed_image.GetLargestPossibleRegion().GetSize()}\")\nprint(\"Image processing complete.\")\n","lang":"python","description":"This quickstart demonstrates how to read an N-dimensional image, apply a common filter (Gaussian smoothing), and write the result back to disk using `itk-core`'s Python bindings. It includes setup for creating a dummy image if no input file exists, making it runnable out-of-the-box."},"warnings":[{"fix":"Ensure your development environment has a C++17 compliant compiler (e.g., GCC >= 7, Clang >= 5, MSVC >= 2017) if compiling from source. For Python users, this is often transparent with `pip install`.","message":"ITK 6.0 (currently in beta) requires C++17. While pre-compiled Python wheels usually handle this, users compiling ITK from source or in specific environments may need to ensure a C++17 compliant compiler is available.","severity":"breaking","affected_versions":">=6.0b01"},{"fix":"Consider `pip install itk` if you encounter missing modules or desire broader ITK functionality beyond the absolute core.","message":"The `itk` PyPI package is a metapackage that installs `itk-core` along with other common ITK modules (e.g., `itk-io`, `itk-filtering`). While `pip install itk-core` works for core functionality, `pip install itk` is generally recommended for a complete ITK Python experience.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Process images in chunks, use memory-efficient data types (e.g., `itk.UC` for unsigned char if appropriate), or ensure sufficient RAM for your image sizes. Use `itk.GetArrayFromImage()` and `itk.GetImageFromArray()` carefully if converting large images to/from NumPy arrays, as this can double memory usage temporarily.","message":"ITK operates on N-dimensional images, and memory consumption can be significant for large 3D or 4D datasets. Unmanaged memory usage can quickly lead to `MemoryError` or system slowdowns.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'5.4':52 '5.4.5':57 '6.0':64 'activ':59 'architectur':30 'bind':40 'c':44 'comput':77,79 'computer-vis':78 'core':4,34,45 'cross':12 'cross-platform':11 'current':49 'cycl':56 'develop':60 'dimension':18,74 'function':46 'fundament':38 'imag':20,67,71 'image-process':66 'insight':2 'itk':1,5,33,42 'itk-cor':32 'mainten':54 'major':63 'medic':70 'medical-imag':69 'n':17,73 'n-dimension':16,72 'open':9 'open-sourc':8 'orient':29 'packag':35 'platform':13 'process':21,68,83 'provid':36 'python':39 'registr':24 'releas':55,65 'scientif':19,76 'scientific-comput':75 'segment':22 'signal':82 'signal-process':81 'sourc':10 'spatial':28 'spatially-ori':27 'toolkit':3,14 'vision':80 'x':53","created_at":"2026-04-17T01:20:59.251006+00:00","updated_at":"2026-04-17T01:20:59.251006+00:00","problems":[{"fix":"The correct import for ITK core functionality is `import itk`, regardless of whether `itk-core` or `itk` was installed via pip.","cause":"Attempting to import the Python module using the PyPI package name `itk_core`.","error":"ModuleNotFoundError: No module named 'itk_core'"},{"fix":"Ensure that your input images and chosen filters operate on consistent dimensions. Explicitly define `ImageType` using `itk.Image[itk.F, N_DIMENSIONS]` where `N_DIMENSIONS` matches your image data.","cause":"Applying an ITK filter or operation that expects a specific image dimension (e.g., 3D) to an image of a different dimension (e.g., 2D), or mismatching dimensions in image processing pipelines.","error":"itk.Exception: Image dimension mismatch"},{"fix":"Reduce image size, process in smaller regions, use memory-efficient data types (e.g., `itk.UC` for `unsigned char`), or upgrade system RAM. Be mindful when converting between `itk.Image` and `numpy.ndarray` as this can temporarily duplicate data.","cause":"Attempting to load or process an image that exceeds available system memory, often with large 3D/4D datasets or when copying images to/from NumPy arrays.","error":"MemoryError: Unable to allocate XXXXX bytes"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"5.4.6","cli_name":"","cli_version":null,"type":"library","homepage":"https://docs.itk.org/","github":"https://github.com/InsightSoftwareConsortium/ITK","docs":null,"changelog":null,"pypi":"https://pypi.org/project/itk-core/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}