.
This commit is contained in:
+40
-1
@@ -6,6 +6,8 @@ from io import BytesIO
|
|||||||
from PIL import Image, ImageFile
|
from PIL import Image, ImageFile
|
||||||
|
|
||||||
import pydicom
|
import pydicom
|
||||||
|
import sys
|
||||||
|
import glob
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .pydicom_PIL import get_PIL_image
|
from .pydicom_PIL import get_PIL_image
|
||||||
@@ -71,4 +73,41 @@ def pil_dicom_image(source, exif_orientation=True, **options):
|
|||||||
def show_PIL(dataset):
|
def show_PIL(dataset):
|
||||||
"""Display an image using the Python Imaging Library (PIL)"""
|
"""Display an image using the Python Imaging Library (PIL)"""
|
||||||
im = get_PIL_image(dataset)
|
im = get_PIL_image(dataset)
|
||||||
im.show()
|
im.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_dicom_order(path):
|
||||||
|
# load the DICOM files
|
||||||
|
files = []
|
||||||
|
|
||||||
|
for fname in glob.glob(path, recursive=False):
|
||||||
|
print("loading: {}".format(fname))
|
||||||
|
files.append((fname, pydicom.dcmread(fname)))
|
||||||
|
|
||||||
|
print("file count: {}".format(len(files)))
|
||||||
|
|
||||||
|
# skip files with no SliceLocation (eg scout views)
|
||||||
|
slices = []
|
||||||
|
map = {}
|
||||||
|
skipcount = 0
|
||||||
|
for fname, f in files:
|
||||||
|
print(dir(f))
|
||||||
|
print(fname)
|
||||||
|
if hasattr(f, 'SliceLocation'):
|
||||||
|
slices.append(f)
|
||||||
|
map[f.SliceLocation] = fname
|
||||||
|
else:
|
||||||
|
skipcount = skipcount + 1
|
||||||
|
|
||||||
|
print("skipped, no SliceLocation: {}".format(skipcount))
|
||||||
|
|
||||||
|
# ensure they are in the correct order
|
||||||
|
slices = sorted(slices, key=lambda s: s.SliceLocation)
|
||||||
|
|
||||||
|
#print(slices)
|
||||||
|
for i in slices:
|
||||||
|
print(map[i.SliceLocation])
|
||||||
|
|
||||||
|
get_dicom_order("/home/ross/Downloads/DICOM HEAD/STD4/SER1/*.dcm")
|
||||||
@@ -32,6 +32,8 @@ from generic.models import Examination, Condition, Sign, ExamBase, Plane, Contra
|
|||||||
from easy_thumbnails.files import get_thumbnailer
|
from easy_thumbnails.files import get_thumbnailer
|
||||||
from easy_thumbnails.exceptions import InvalidImageFormatError
|
from easy_thumbnails.exceptions import InvalidImageFormatError
|
||||||
|
|
||||||
|
import pydicom
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
image_storage = FileSystemStorage(
|
image_storage = FileSystemStorage(
|
||||||
@@ -283,6 +285,39 @@ class LongSeries(models.Model):
|
|||||||
"<div>{}<br/>{}<br/>Images: {}</div>", examination, thumb, image_number
|
"<div>{}<br/>{}<br/>Images: {}</div>", examination, thumb, image_number
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def order_by_dicom_location(self):
|
||||||
|
images = self.images.all()
|
||||||
|
|
||||||
|
files = []
|
||||||
|
|
||||||
|
for i in images:
|
||||||
|
files.append((i, pydicom.dcmread(i.image.path)))
|
||||||
|
|
||||||
|
#print("file count: {}".format(len(files)))
|
||||||
|
|
||||||
|
# skip files with no SliceLocation (eg scout views)
|
||||||
|
slices = []
|
||||||
|
map = {}
|
||||||
|
skipcount = 0
|
||||||
|
for i, f in files:
|
||||||
|
if hasattr(f, 'SliceLocation'):
|
||||||
|
slices.append(f)
|
||||||
|
map[f.SliceLocation] = i
|
||||||
|
else:
|
||||||
|
skipcount = skipcount + 1
|
||||||
|
|
||||||
|
print("skipped, no SliceLocation: {}".format(skipcount))
|
||||||
|
|
||||||
|
# ensure they are in the correct order
|
||||||
|
slices = sorted(slices, key=lambda s: s.SliceLocation)
|
||||||
|
|
||||||
|
#print(slices)
|
||||||
|
n = 1
|
||||||
|
for f in slices:
|
||||||
|
i = map[f.SliceLocation]
|
||||||
|
i.position = n
|
||||||
|
i.save()
|
||||||
|
n = n + 1
|
||||||
|
|
||||||
# class LongImage(models.Model):
|
# class LongImage(models.Model):
|
||||||
# long = models.ForeignKey(Long,
|
# long = models.ForeignKey(Long,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ urlpatterns = [
|
|||||||
path("question/", views.LongView.as_view(), name="long_view"),
|
path("question/", views.LongView.as_view(), name="long_view"),
|
||||||
path("series/", views.LongSeriesView.as_view(), name="long_series_view"),
|
path("series/", views.LongSeriesView.as_view(), name="long_series_view"),
|
||||||
path("series/<int:pk>", views.long_series_detail, name="long_series_detail"),
|
path("series/<int:pk>", views.long_series_detail, name="long_series_detail"),
|
||||||
|
path("series/<int:pk>/order_dicom", views.long_series_order_dicom, name="long_series_order_dicom"),
|
||||||
path("series/<int:pk>/delete", views.LongSeriesDelete.as_view(), name="long_series_delete"),
|
path("series/<int:pk>/delete", views.LongSeriesDelete.as_view(), name="long_series_delete"),
|
||||||
# path("unchecked/", views.unchecked_list, name="unchecked_list"),
|
# path("unchecked/", views.unchecked_list, name="unchecked_list"),
|
||||||
# path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
|
# path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
|
||||||
|
|||||||
@@ -930,5 +930,9 @@ def exam_scores_cid_user(request, pk, sk):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def long_series_order_dicom(request, pk):
|
||||||
|
series = get_object_or_404(LongSeries, pk=pk)
|
||||||
|
series.order_by_dicom_location()
|
||||||
|
|
||||||
LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer)
|
LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer)
|
||||||
Reference in New Issue
Block a user