1
+ import { demoServer } from './common.ts'
2
+
3
+ function verifyImage ( image ) {
4
+ cy . expect ( image . imageType . dimension ) . to . equal ( 3 )
5
+ cy . expect ( image . imageType . componentType ) . to . equal ( 'uint16' )
6
+ cy . expect ( image . imageType . pixelType ) . to . equal ( 'Scalar' )
7
+ cy . expect ( image . imageType . components ) . to . equal ( 1 )
8
+ cy . expect ( image . origin [ 0 ] ) . to . equal ( 0.0 )
9
+ cy . expect ( image . origin [ 1 ] ) . to . equal ( 0.0 )
10
+ cy . expect ( image . origin [ 2 ] ) . to . equal ( 2.0 )
11
+ cy . expect ( image . spacing [ 0 ] ) . to . equal ( 0.85935 )
12
+ cy . expect ( image . spacing [ 1 ] ) . to . equal ( 0.85935 )
13
+ cy . expect ( image . spacing [ 2 ] ) . to . equal ( 3.0 )
14
+ cy . expect ( image . size [ 0 ] ) . to . equal ( 256 )
15
+ cy . expect ( image . size [ 1 ] ) . to . equal ( 256 )
16
+ cy . expect ( image . size [ 2 ] ) . to . equal ( 3 )
17
+ cy . expect ( image . data . length ) . to . equal ( 3 * 65536 )
18
+ cy . expect ( image . data [ 1000 ] ) . to . equal ( 0 )
19
+ }
20
+
21
+ const zSpacing = 3.0
22
+ const zOrigin = 2.0
23
+ const testImageFiles = [
24
+ 'mri3D_01.png' ,
25
+ 'mri3D_02.png' ,
26
+ 'mri3D_03.png' ,
27
+ ]
28
+
29
+ describe ( 'meta-image' , ( ) => {
30
+ beforeEach ( function ( ) {
31
+ cy . visit ( demoServer )
32
+
33
+ const testPathPrefix = '../test/data/input/PNGSeries/'
34
+
35
+ cy . window ( ) . then ( ( win ) => {
36
+ win . testImageFiles = { }
37
+ } )
38
+ testImageFiles . forEach ( ( fileName ) => {
39
+ cy . readFile ( `${ testPathPrefix } ${ fileName } ` , null ) . as ( fileName )
40
+ cy . window ( ) . then ( ( win ) => {
41
+ win . testImageFiles [ fileName ] = this [ fileName ]
42
+ } )
43
+ } )
44
+ } )
45
+
46
+ it ( 'Reads a sorted PNG file series' , function ( ) {
47
+ cy . window ( ) . then ( async ( win ) => {
48
+ const files = testImageFiles . map ( ( fileName ) => {
49
+ return { data : new Uint8Array ( win . testImageFiles [ fileName ] ) , path : fileName }
50
+ } )
51
+ const sortedSeries = true
52
+
53
+ const { image, webWorkerPool } = await win . imageIo . readImageFileSeries ( files , { zSpacing, zOrigin, sortedSeries } )
54
+ webWorkerPool . terminateWorkers ( )
55
+ verifyImage ( image )
56
+ } )
57
+ } )
58
+
59
+ it ( 'Reads sorted PNG file series, specify componentType, pixelType' , function ( ) {
60
+ cy . window ( ) . then ( async ( win ) => {
61
+ const files = testImageFiles . map ( ( fileName ) => {
62
+ return { data : new Uint8Array ( win . testImageFiles [ fileName ] ) , path : fileName }
63
+ } )
64
+ const sortedSeries = true
65
+ const componentType = win . itk . IntTypes . Int32
66
+ const pixelType = win . itk . PixelTypes . Vector
67
+
68
+ const { image, webWorkerPool } = await win . imageIo . readImageFileSeries ( files , { zSpacing, zOrigin, sortedSeries, componentType, pixelType } )
69
+ webWorkerPool . terminateWorkers ( )
70
+ cy . expect ( image . imageType . componentType ) . to . equal ( 'int32' )
71
+ cy . expect ( image . imageType . pixelType ) . to . equal ( 'Vector' )
72
+ } )
73
+ } )
74
+
75
+ it ( 'Reads an unsorted PNG file series' , function ( ) {
76
+ cy . window ( ) . then ( async ( win ) => {
77
+ const files = testImageFiles . map ( ( fileName ) => {
78
+ return { data : new Uint8Array ( win . testImageFiles [ fileName ] ) , path : fileName }
79
+ } )
80
+ files . reverse ( )
81
+
82
+ const { image, webWorkerPool } = await win . imageIo . readImageFileSeries ( files , { zSpacing, zOrigin } )
83
+ webWorkerPool . terminateWorkers ( )
84
+ verifyImage ( image )
85
+ } )
86
+ } )
87
+
88
+ it ( 'Reads an unsorted PNG file series, specifying componentType, pixelType' , function ( ) {
89
+ cy . window ( ) . then ( async ( win ) => {
90
+ const files = testImageFiles . map ( ( fileName ) => {
91
+ return { data : new Uint8Array ( win . testImageFiles [ fileName ] ) , path : fileName }
92
+ } )
93
+ files . reverse ( )
94
+ const componentType = win . itk . IntTypes . Int32
95
+ const pixelType = win . itk . PixelTypes . Vector
96
+
97
+ const { image, webWorkerPool } = await win . imageIo . readImageFileSeries ( files , { zSpacing, zOrigin, componentType, pixelType } )
98
+ webWorkerPool . terminateWorkers ( )
99
+ cy . expect ( image . imageType . componentType ) . to . equal ( 'int32' )
100
+ cy . expect ( image . imageType . pixelType ) . to . equal ( 'Vector' )
101
+ } )
102
+ } )
103
+ } )
0 commit comments