Mercurial > hg > orthanc-tests
changeset 253:74c693e093ce
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Aug 2019 17:44:25 +0200 |
parents | 01db33301c3d |
children | 05b77ade5e1d |
files | Plugins/WSI/Run.py |
diffstat | 1 files changed, 83 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/WSI/Run.py Fri Aug 02 16:12:39 2019 +0200 +++ b/Plugins/WSI/Run.py Fri Aug 02 17:44:25 2019 +0200 @@ -92,21 +92,39 @@ password = args.password, restPort = args.rest) -def CallDicomizer(suffix): +def CallCommand(command): prefix = [] if args.valgrind: prefix = [ 'valgrind' ] - log = subprocess.check_output(prefix + [ args.dicomizer, - '--username=%s' % args.username, - '--password=%s' % args.password ] + suffix, + log = subprocess.check_output(prefix + command, stderr=subprocess.STDOUT) - + # If using valgrind, only print the lines from the log starting # with '==' (they contain the report from valgrind) if args.valgrind: print('\n'.join(filter(lambda x: x.startswith('=='), log.splitlines()))) + +def CallDicomizer(suffix): + CallCommand([ args.dicomizer, + '--username=%s' % args.username, + '--password=%s' % args.password ] + suffix) + + +def CallDicomToTiff(suffix): + CallCommand([ args.to_tiff ] + suffix) + + +def CallTiffInfoOnSeries(series): + with tempfile.NamedTemporaryFile(delete = False) as temp: + temp.close() + CallDicomToTiff([ series, temp.name ]) + tiff = subprocess.check_output([ 'tiffinfo', temp.name ]) + os.unlink(temp.name) + + return tiff + class Orthanc(unittest.TestCase): def setUp(self): @@ -148,6 +166,11 @@ self.assertEqual(1, pyramid['TilesCount'][0][0]) self.assertEqual(1, pyramid['TilesCount'][0][1]) + tiff = CallTiffInfoOnSeries(s[0]) + p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) + self.assertEqual(1, len(p)) + self.assertTrue('YCbCr' in p[0]) + def test_grayscale_pyramid(self): CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--tile-width=64', '--tile-height=64' ]) @@ -193,6 +216,61 @@ self.assertEqual(2, pyramid['TilesCount'][2][1]) self.assertEqual(1, pyramid['TilesCount'][3][0]) self.assertEqual(1, pyramid['TilesCount'][3][1]) + + tiff = CallTiffInfoOnSeries(s[0]) + p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) + self.assertEqual(4, len(p)) + for j in range(4): + self.assertTrue('min-is-black' in p[j]) + + + def test_import_tiff_grayscale(self): + CallDicomizer([ GetDatabasePath('WSI/LenaGrayscaleJpeg.tiff') ]) + + s = DoGet(ORTHANC, '/series') + self.assertEqual(1, len(s)) + + pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) + self.assertEqual(4, len(pyramid['Resolutions'])) + + tiff = CallTiffInfoOnSeries(s[0]) + p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) + self.assertEqual(4, len(p)) + for j in range(4): + self.assertTrue('min-is-black' in p[j]) + + + def test_import_tiff_ycbcr(self): + CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegYCbCr.tiff') ]) + + s = DoGet(ORTHANC, '/series') + self.assertEqual(1, len(s)) + + pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) + self.assertEqual(4, len(pyramid['Resolutions'])) + + tiff = CallTiffInfoOnSeries(s[0]) + p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) + self.assertEqual(4, len(p)) + for j in range(4): + self.assertTrue('YCbCr' in p[j]) + + + def test_import_tiff_rgb(self): + CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegRGB.tiff') ]) + + s = DoGet(ORTHANC, '/series') + self.assertEqual(1, len(s)) + + pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) + self.assertEqual(4, len(pyramid['Resolutions'])) + + tiff = CallTiffInfoOnSeries(s[0]) + p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) + self.assertEqual(4, len(p)) + for j in range(4): + self.assertTrue('RGB' in p[j]) + try: print('\nStarting the tests...')