diff Tests/Tests.py @ 436:9f87d5b2b382

added test_dicom_seg
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Nov 2021 15:26:37 +0100
parents cb579ad96a6c
children e769bcf2b94f
line wrap: on
line diff
--- a/Tests/Tests.py	Tue Aug 31 11:02:35 2021 +0200
+++ b/Tests/Tests.py	Thu Nov 25 15:26:37 2021 +0100
@@ -8195,3 +8195,35 @@
         self.assertEqual(127 + 2 * 16, im.getpixel((0, 1)))
         self.assertEqual(127 + 2 * 32, im.getpixel((1, 1)))
 
+
+    def test_dicom_seg(self):
+        # This test fails in Orthanc <= 1.9.7
+        a = UploadInstance(_REMOTE, 'DicomSeg.dcm') ['ID']
+        
+        self.assertEqual(96, len(DoGet(_REMOTE, '/instances/%s/frames' % a)))
+        self.assertRaises(Exception, lambda: DoGet(_REMOTE, '/instances/%s/frames/96/preview' % a))
+
+        nonEmptyFrames = [ 11, 12, 13, 14, 15, 16, 39, 40, 42, 43, 44, 45,
+                           46, 47, 48, 49, 75, 76, 77, 78, 79, 80, 81 ]
+        
+        for i in range(96):
+            im = GetImage(_REMOTE, '/instances/%s/frames/%d/preview' % (a, i))
+            self.assertEqual('L', im.mode)
+            self.assertEqual(256, im.size[0])
+            self.assertEqual(256, im.size[1])
+
+            e = im.getextrema()
+            self.assertEqual(0, e[0])
+
+            if e[1] == 0:
+                self.assertFalse(i in nonEmptyFrames)
+            else:
+                self.assertTrue(i in nonEmptyFrames)
+
+        im1 = GetImage(_REMOTE, '/instances/%s/frames/44/preview' % a)
+
+        # Generated by "dcm2pnm +F 45 DicomSeg.dcm DicomSeg-Frame45.pgm"
+        im2 = Image.open(GetDatabasePath('DicomSeg-Frame45.pgm'))
+        im2 = im2.point(lambda p: 255 if p == 128 else 0)
+
+        self.assertTrue(ImageChops.difference(im1, im2).getbbox() is None)