coveralls: 
[![Coverage Status](https://coveralls.io/builds/12238080/badge)](https://coveralls.io/builds/12238080)

Coverage increased (+0.2%) to 78.728% when pulling **2e5c6eaa68957507ad19205cfbc872dbb3011ace on 62_voxel_mask** into **a70490c09196d7996ecfd99401eb68765ae25a67 on master**.

diff --git a/suspect/image/__init__.py b/suspect/image/__init__.py
index 14e78f7..cffdc25 100644
--- a/suspect/image/__init__.py
+++ b/suspect/image/__init__.py
@@ -1,1 +1,2 @@
-from suspect.image._image import *
\ No newline at end of file
+from suspect.image._image import *
+from ._mask import create_mask
\ No newline at end of file
diff --git a/suspect/image/_mask.py b/suspect/image/_mask.py
new file mode 100644
index 0000000..e31cff1
--- /dev/null
+++ b/suspect/image/_mask.py
@@ -0,0 +1,46 @@
+import numpy as np
+
+
+def create_mask(source_image, ref_image, voxels=None):
+    """
+    Creates a volumetric mask for the source_image voxel in the coordinate
+    system of the ref_image volume.
+    
+    Parameters
+    ----------
+    source_image : MRSBase
+        The spectroscopy volume from which to create the mask.
+    ref_image : ImageBase
+        The reference image volume which defines the coordinate system for
+        the mask.
+    
+    Returns
+    -------
+    numpy.ndarray
+        Boolean array with the same shape as ref_image, True for all voxels
+        inside source_image, false for all others.
+    """
+
+    # create a grid of coordinates for all points in the ref_image
+    # the ref_image has coord index order [z, y, x] so we reverse the shape
+    # to get the indices in (x, y, z) format for the coordinate conversion
+    ref_coords = np.mgrid[[range(0, size) for size in ref_image.shape[::-1]]]
+
+    # mgrid puts the (x, y, z) tuple at the front, we want it at the back
+    ref_coords = np.moveaxis(ref_coords, 0, -1)
+
+    # now we can apply to_scanner and from_scanner to convert from ref coords
+    # into source coords
+    scanner_coords = ref_image.to_scanner(ref_coords)
+    source_coords = source_image.from_scanner(scanner_coords)
+
+    # now check whether the source_coords are in the selected voxel
+    # TODO for now, we assume single voxel data until issue 50 is resolved
+
+    # have to transpose the result to get it to match the shape of ref_image
+    return np.all((source_coords[..., 0] < 0.5,
+                   source_coords[..., 0] >= -0.5,
+                   source_coords[..., 1] >= -0.5,
+                   source_coords[..., 2] >= -0.5,
+                   source_coords[..., 1] < 0.5,
+                   source_coords[..., 2] < 0.5), axis=0).T

ENH: Mask function for voxel on image
It should be possible to call a `create_mask()` function which produces a binary mask showing which voxels of a reference image are inside a spectroscopy voxel. In the default case this would be for all the voxels in the spectroscopy, but it should also be possible to specify a specific voxel or list of voxels to be used instead, so that masks for individual CSI voxels are also possible.
diff --git a/tests/test_mrs/test_image.py b/tests/test_mrs/test_image.py
new file mode 100644
index 0000000..70fca64
--- /dev/null
+++ b/tests/test_mrs/test_image.py
@@ -0,0 +1,23 @@
+import suspect
+
+import suspect._transforms
+
+import numpy as np
+
+
+def test_simple_mask():
+    source_transform = suspect._transforms.transformation_matrix([1, 0, 0],
+                                                                 [0, 1, 0],
+                                                                 [5, 0, 0],
+                                                                 [10, 10, 10])
+    ref_transform = suspect._transforms.transformation_matrix([1, 0, 0],
+                                                              [0, 1, 0],
+                                                              [-10, -5, -5],
+                                                              [1, 1, 1])
+    source_volume = suspect.MRSBase(np.ones(1024), 1e-3, 123, transform=source_transform)
+    ref_volume = suspect.base.ImageBase(np.zeros((20, 20, 20)), transform=ref_transform)
+    mask = suspect.image.create_mask(source_volume, ref_volume)
+    assert ref_volume.shape == mask.shape
+    mask_target = np.zeros_like(ref_volume)
+    mask_target[0:10, 0:10, 10:20] = 1
+    np.testing.assert_equal(mask_target.astype('bool'), mask)

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov
apt-get update apt-get install -y gcc
3.5
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
asteval==0.9.26
async-generator==1.10
attrs==22.2.0
Babel==2.11.0
backcall==0.2.0
bleach==4.1.0
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
decorator==5.1.1
defusedxml==0.7.1
docutils==0.18.1
entrypoints==0.4
future==1.0.0
idna==3.10
imagesize==1.4.1
importlib-metadata==4.8.3
iniconfig==1.1.1
ipykernel==5.5.6
ipython==7.16.3
ipython-genutils==0.2.0
jedi==0.17.2
Jinja2==3.0.3
jsonschema==3.2.0
jupyter-client==7.1.2
jupyter-core==4.9.2
jupyterlab-pygments==0.1.2
lmfit==1.0.3
MarkupSafe==2.0.1
mistune==0.8.4
nbclient==0.5.9
nbconvert==6.0.7
nbformat==5.1.3
nbsphinx==0.8.8
nest-asyncio==1.6.0
numpy==1.19.5
packaging==21.3
pandocfilters==1.5.1
parse==1.20.2
Parsley==1.3
parso==0.7.1
pexpect==4.9.0
pickleshare==0.7.5
pluggy==1.0.0
prompt-toolkit==3.0.36
ptyprocess==0.7.0
py==1.11.0
pydicom==2.3.1
Pygments==2.14.0
pyparsing==3.1.4
pyrsistent==0.18.0
pytest==7.0.1
pytest-cov==4.0.0
python-dateutil==2.9.0.post0
pytz==2025.2
PyWavelets==1.1.1
pyzmq==25.1.2
requests==2.27.1
scipy==1.5.4
six==1.17.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
-e git+https://github.com/openmrslab/suspect.git@a70490c09196d7996ecfd99401eb68765ae25a67#egg=suspect
testpath==0.6.0
tomli==1.2.3
tornado==6.1
traitlets==4.3.3
typing_extensions==4.1.1
uncertainties==3.1.7
urllib3==1.26.20
wcwidth==0.2.13
webencodings==0.5.1
zipp==3.6.0

name: suspect
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - asteval==0.9.26
      - async-generator==1.10
      - attrs==22.2.0
      - babel==2.11.0
      - backcall==0.2.0
      - bleach==4.1.0
      - charset-normalizer==2.0.12
      - coverage==6.2
      - decorator==5.1.1
      - defusedxml==0.7.1
      - docutils==0.18.1
      - entrypoints==0.4
      - future==1.0.0
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - ipykernel==5.5.6
      - ipython==7.16.3
      - ipython-genutils==0.2.0
      - jedi==0.17.2
      - jinja2==3.0.3
      - jsonschema==3.2.0
      - jupyter-client==7.1.2
      - jupyter-core==4.9.2
      - jupyterlab-pygments==0.1.2
      - lmfit==1.0.3
      - markupsafe==2.0.1
      - mistune==0.8.4
      - nbclient==0.5.9
      - nbconvert==6.0.7
      - nbformat==5.1.3
      - nbsphinx==0.8.8
      - nest-asyncio==1.6.0
      - numpy==1.19.5
      - packaging==21.3
      - pandocfilters==1.5.1
      - parse==1.20.2
      - parsley==1.3
      - parso==0.7.1
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pluggy==1.0.0
      - prompt-toolkit==3.0.36
      - ptyprocess==0.7.0
      - py==1.11.0
      - pydicom==2.3.1
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pyrsistent==0.18.0
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pywavelets==1.1.1
      - pyzmq==25.1.2
      - requests==2.27.1
      - scipy==1.5.4
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - testpath==0.6.0
      - tomli==1.2.3
      - tornado==6.1
      - traitlets==4.3.3
      - typing-extensions==4.1.1
      - uncertainties==3.1.7
      - urllib3==1.26.20
      - wcwidth==0.2.13
      - webencodings==0.5.1
      - zipp==3.6.0
prefix: /opt/conda/envs/suspect

tests/test_mrs/test_image.py::test_simple_mask
suspect/image/_mask.py suspect/image/__init__.py
suspect/image/_mask.py suspect/image/__init__.py