Skip to content

Commit

Permalink
Merge pull request #158 from QIB-Sheffield/development
Browse files Browse the repository at this point in the history
v0.2.4
  • Loading branch information
plaresmedima authored Jan 10, 2025
2 parents 1bf4913 + 0311fb9 commit 732fb6c
Show file tree
Hide file tree
Showing 12 changed files with 443 additions and 2,951 deletions.
63 changes: 0 additions & 63 deletions dev/manage.py

This file was deleted.

4 changes: 2 additions & 2 deletions dev/sops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ Creating a new release (from a fork)
Creating a PyPi release
-----------------------

In the terminal, cd to the /mdreg directory, and:
In the terminal, cd to the /dbdicom directory, and:

>>> python -m build
>>> twine upload dist/*

When prompted for user name, enter __token__

As password paste the API token generated in PyPi mdreg repository
settings (https://pypi.org/manage/project/mdreg/settings/).
settings (https://pypi.org/manage/project/dbdicom/settings/).
Note: Paste with Ctrl-V does not work in Windows. Use Edit > Paste via the menu.

4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = 'dbdicom'
copyright = '2022, QIB-Sheffield'
copyright = '2022-2025, QIB-Sheffield'
author = 'QIB-Sheffield'
release = '0.2.3'
release = '0.2.4'

# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requires = ['setuptools>=61.2']

[project]
name = "dbdicom"
version = "0.2.3"
version = "0.2.4"
dependencies = [
"matplotlib",
"nibabel",
Expand All @@ -19,6 +19,7 @@ dependencies = [
"importlib-resources", #necessary?
'scipy',
'imageio',
'vreg',
]

# optional information
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ pydicom
python-gdcm
pylibjpeg-libjpeg
importlib-resources
scipy
imageio
vreg
3 changes: 2 additions & 1 deletion src/dbdicom/ds/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,22 @@ def new_uid(n=None):
return [pydicom.uid.generate_uid() for _ in range(n)]


# Obsolete - replaced by instance.affine()
def get_affine_matrix(ds):
"""Affine transformation matrix for a DICOM image"""

# slice_spacing = get_values(ds, 'SpacingBetweenSlices')
# if slice_spacing is None:
# slice_spacing = get_values(ds, 'SliceThickness')
slice_spacing = get_values(ds, 'SliceThickness')

return image.affine_matrix(
get_values(ds, 'ImageOrientationPatient'),
get_values(ds, 'ImagePositionPatient'),
get_values(ds, 'PixelSpacing'),
slice_spacing)


# Obsolete - replaced by instance.set_affine()
def set_affine_matrix(ds, affine):
v = image.dismantle_affine_matrix(affine)
set_values(ds, 'PixelSpacing', v['PixelSpacing'])
Expand Down
1 change: 0 additions & 1 deletion src/dbdicom/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
scipy,
skimage,
sklearn,
vreg,
matplotlib,
)
2 changes: 1 addition & 1 deletion src/dbdicom/extensions/vreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd
import scipy
import dbdicom
from dbdicom.utils import vreg
import vreg
from dbdicom import Series


Expand Down
65 changes: 43 additions & 22 deletions src/dbdicom/types/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import nibabel as nib
import pandas as pd
import matplotlib.pyplot as plt
import vreg


from dbdicom.record import Record
Expand Down Expand Up @@ -39,31 +40,12 @@ def copy_to_series(self, series):
uid = self.manager.copy_instance_to_series(self.key(), series.keys(), series)
return self.record('Instance', uid)

def array(self):
def pixel_values(self):
return self.get_pixel_array()

def get_pixel_array(self):
ds = self.get_dataset()
return ds.get_pixel_array()

def set_array(self, array): # obsolete
self.set_pixel_array(array)

def set_pixel_values(self, array):
self.set_pixel_array(array)

def set_pixel_array(self, array): # make private
ds = self.get_dataset()
if ds is None:
ds = new_dataset('MRImage')
ds.set_pixel_array(array)
in_memory = self.key() in self.manager.dataset
self.set_dataset(ds)
# This bit added ad-hoc because set_dataset() places the datset in memory
# So if the instance is not in memory, it needs to be written and removed again
if not in_memory:
self.clear()

def set_dataset(self, dataset):
self._key = self.manager.set_instance_dataset(self.uid, dataset, self.key())

Expand Down Expand Up @@ -141,18 +123,57 @@ def BGRA_array(self):
center = self.WindowCenter,
)

def volume(self):
return vreg.volume(self.pixel_values(),
self.affine())

def set_volume(self, volume:vreg.Volume3D):
self.set_pixel_values(np.squeeze(volume.values))
self.set_affine(volume.affine)

def affine(self):
return image.affine_matrix(self.ImageOrientationPatient,
self.ImagePositionPatient,
self.PixelSpacing,
self.SliceThickness)

def set_affine(self, affine):
p = image.dismantle_affine_matrix(affine)
self.read()
self.SpacingBetweenSlices = p['SpacingBetweenSlices']
self.SliceThickness = p['SpacingBetweenSlices']
#self.SpacingBetweenSlices = p['SpacingBetweenSlices']
self.SliceThickness = p['SliceThickness']
self.PixelSpacing = p['PixelSpacing']
self.ImageOrientationPatient = p['ImageOrientationPatient']
self.ImagePositionPatient = p['ImagePositionPatient']
self.SliceLocation = np.dot(p['ImagePositionPatient'], p['slice_cosine'])
self.clear()


# OBSOLETE API

def array(self): # obsolete replace by pixel_values
return self.get_pixel_array()

def get_pixel_array(self): # obsolete replace by pixel_values
ds = self.get_dataset()
return ds.get_pixel_array()

def set_array(self, array): # obsolete replace by set_pixel_values
self.set_pixel_array(array)

def set_pixel_array(self, array): # obsolete replace by set_pixel_values
ds = self.get_dataset()
if ds is None:
ds = new_dataset('MRImage')
ds.set_pixel_array(array)
in_memory = self.key() in self.manager.dataset
self.set_dataset(ds)
# This bit added ad-hoc because set_dataset() places the datset in memory
# So if the instance is not in memory, it needs to be written and removed again
if not in_memory:
self.clear()


def map_to(source, target):
"""Map non-zero image pixels onto a target image.
Expand Down
Loading

0 comments on commit 732fb6c

Please sign in to comment.