Skip to content

Commit

Permalink
feat(readImageDICOMFileSeries): Support componentType, pixelType options
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Nov 7, 2022
1 parent d42fbc1 commit 5e5d142
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
7 changes: 7 additions & 0 deletions src/io/ReadImageDICOMFileSeriesOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import CastImageOptions from '../core/CastImageOptions.js'

interface ReadImageDICOMFileSeriesOptions extends CastImageOptions {
singleSortedSeries?: boolean
}

export default ReadImageDICOMFileSeriesOptions
1 change: 1 addition & 0 deletions src/io/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export { default as readImageHTTP } from './../readImageHTTP.js'

export { default as readDICOMTags } from './../readDICOMTags.js'
export { default as readDICOMTagsArrayBuffer } from './../readDICOMTagsArrayBuffer.js'
export { default as ReadImageDICOMFileSeriesOptions } from './../ReadImageDICOMFileSeriesOptions.js'
export { default as readImageDICOMFileSeries } from './../readImageDICOMFileSeries.js'
export { default as ReadImageDICOMArrayBufferSeriesOptions } from './../ReadImageDICOMArrayBufferSeriesOptions.js'
export { default as readImageDICOMArrayBufferSeries } from './../readImageDICOMArrayBufferSeries.js'
Expand Down
16 changes: 14 additions & 2 deletions src/io/readImageDICOMFileSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ import { readAsArrayBuffer } from 'promise-file-reader'

import ReadImageFileSeriesResult from './ReadImageFileSeriesResult.js'
import readImageDICOMArrayBufferSeries from './readImageDICOMArrayBufferSeries.js'
import ReadImageDICOMFileSeriesOptions from './ReadImageDICOMFileSeriesOptions.js'
import ReadImageDICOMArrayBufferSeriesOptions from './ReadImageDICOMArrayBufferSeriesOptions.js'

const readImageDICOMFileSeries = async (
fileList: FileList | File[],
singleSortedSeries = false
options?: ReadImageDICOMFileSeriesOptions | boolean
): Promise<ReadImageFileSeriesResult> => {
const fetchFileContents = Array.from(fileList, async function (file) {
return await readAsArrayBuffer(file)
})
const fileContents: ArrayBuffer[] = await Promise.all(fetchFileContents)

let optionsToPass: ReadImageDICOMArrayBufferSeriesOptions = {}
if (typeof options === 'object') {
optionsToPass = options
}
if (typeof options === 'boolean') {
// Backwards compatibility
optionsToPass.singleSortedSeries = options
}

const fileNames = Array.from(fileList, (file) => file.name)
return await readImageDICOMArrayBufferSeries(fileContents, singleSortedSeries, fileNames)
optionsToPass.fileNames = fileNames
return readImageDICOMArrayBufferSeries(fileContents, optionsToPass)
}

export default readImageDICOMFileSeries
61 changes: 44 additions & 17 deletions test/browser/io/DICOMSeriesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function verifyImage (t, image, expectedComponentType, expectedPixelType) {
}

export default function () {
test('Test reading DICOM file series', t => {
test('Test reading DICOM file series', async t => {
const fetchFiles = fileNames.map(function (file) {
const path = testSeriesDirectory + file
return axios.get(path, { responseType: 'blob' }).then(function (response) {
Expand All @@ -52,17 +52,13 @@ export default function () {
})
})

return Promise.all(fetchFiles)
.then(function (files) {
return readImageDICOMFileSeries(files)
})
.then(function ({ image, webWorkerPool }) {
webWorkerPool.terminateWorkers()
verifyImage(t, image)
})
const files = await Promise.all(fetchFiles)
const { image, webWorkerPool } = await readImageDICOMFileSeries(files)
webWorkerPool.terminateWorkers()
verifyImage(t, image)
})

test('Test reading DICOM file series, assume a single sorted series', t => {
test('Test reading DICOM file series, given componentType, pixelType', async t => {
const fetchFiles = fileNames.map(function (file) {
const path = testSeriesDirectory + file
return axios.get(path, { responseType: 'blob' }).then(function (response) {
Expand All @@ -71,15 +67,46 @@ export default function () {
})
})

return Promise.all(fetchFiles)
.then(function (files) {
const singleSortedSeries = true
return readImageDICOMFileSeries(files, singleSortedSeries)
const files = await Promise.all(fetchFiles)
const componentType = IntTypes.Int32
const pixelType = PixelTypes.Vector
const { image, webWorkerPool } = await readImageDICOMFileSeries(files, { componentType, pixelType })
webWorkerPool.terminateWorkers()
verifyImage(t, image, componentType, pixelType)
})

test('Test reading DICOM file series, assume a single sorted series', async t => {
const fetchFiles = fileNames.map(function (file) {
const path = testSeriesDirectory + file
return axios.get(path, { responseType: 'blob' }).then(function (response) {
const jsFile = new window.File([response.data], file)
return jsFile
})
.then(function ({ image, webWorkerPool }) {
webWorkerPool.terminateWorkers()
verifyImage(t, image)
})

const files = await Promise.all(fetchFiles)
const singleSortedSeries = true
const { image, webWorkerPool } = await readImageDICOMFileSeries(files, singleSortedSeries)
webWorkerPool.terminateWorkers()
verifyImage(t, image)
})

test('Test reading DICOM file series, assume a single sorted series, given componentType, pixelType', async t => {
const fetchFiles = fileNames.map(function (file) {
const path = testSeriesDirectory + file
return axios.get(path, { responseType: 'blob' }).then(function (response) {
const jsFile = new window.File([response.data], file)
return jsFile
})
})

const files = await Promise.all(fetchFiles)
const singleSortedSeries = true
const componentType = IntTypes.Int32
const pixelType = PixelTypes.Vector
const { image, webWorkerPool } = await readImageDICOMFileSeries(files, { singleSortedSeries, componentType, pixelType })
webWorkerPool.terminateWorkers()
verifyImage(t, image, componentType, pixelType)
})

test('Test reading DICOM array buffer series', async t => {
Expand Down

0 comments on commit 5e5d142

Please sign in to comment.