Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/utilities/getPixelSpacingInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function calculateUSPixelSpacing(instance) {

return {
PixelSpacing: USPixelSpacing,
type: null,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import { calculateNeighborhoodStats } from './calculateNeighborhoodStats';
import getPixelSpacingInformation from './getPixelSpacingInformation';
import { asArray } from './asArray';
export { updatePlaneRestriction } from './updatePlaneRestriction';
export * from './toNumber';

const getViewportModality = (viewport: IViewport, volumeId?: string) =>
_getViewportModality(viewport, volumeId, cache.getVolume);
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/utilities/toNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Returns the values as an array of javascript numbers
*
* @param val - The javascript object for the specified element in the metadata
* @returns {*}
*/
export function toNumber(val) {
if (Array.isArray(val)) {
return [...val].map((v) => (v !== undefined ? Number(v) : v));
} else {
return val !== undefined ? Number(val) : val;
}
}

export default toNumber;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { capitalizeTag } from '../shared/tagCase';
/**
* Retrieves metadata from a DICOM image and returns it as an object with capitalized keys.
* @param imageId - the imageId
Expand Down Expand Up @@ -29,9 +30,6 @@ function getInstanceModule(imageId, metaDataProvider, types) {
return result;
}

const capitalizeTag = (tag: string) =>
tag.charAt(0).toUpperCase() + tag.slice(1);

const instanceModuleNames = [
'multiframeModule',
'generalSeriesModule',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import {
instanceModuleNames,
} from '../../getInstanceModule';
import { getUSEnhancedRegions } from './USHelpers';
import { Modules } from '../../../shared/Tags';
const { calibratedPixelSpacingMetadataProvider } = utilities;

function metaDataProvider(type, imageId) {
const { MetadataModules } = Enums;
const { MetadataModules } = Enums;

function metaDataProvider(type, imageId) {
if (type === MetadataModules.MULTIFRAME) {
// the get function removes the PerFrameFunctionalGroupsSequence
const { metadata, frame } = retrieveMultiframeMetadataImageId(imageId);
Expand Down Expand Up @@ -66,6 +68,10 @@ function metaDataProvider(type, imageId) {
return;
}

if (Modules[type]) {
return Modules[type].fromMetadata(metaData);
}

if (type === MetadataModules.GENERAL_STUDY) {
return {
studyDescription: getValue<string>(metaData['00081030']),
Expand Down Expand Up @@ -97,16 +103,6 @@ function metaDataProvider(type, imageId) {
};
}

if (type === MetadataModules.GENERAL_IMAGE) {
return {
sopInstanceUID: getValue<string>(metaData['00080018']),
instanceNumber: getNumberValue(metaData['00200013']),
lossyImageCompression: getValue<string>(metaData['00282110']),
lossyImageCompressionRatio: getNumberValue(metaData['00282112']),
lossyImageCompressionMethod: getValue<string>(metaData['00282114']),
};
}

if (type === MetadataModules.PATIENT) {
return {
patientID: getValue<string>(metaData['00100020']),
Expand Down Expand Up @@ -142,73 +138,6 @@ function metaDataProvider(type, imageId) {
};
}

if (type === MetadataModules.IMAGE_PLANE) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has been moved to shared code between different types of instance data.

//metaData = fixNMMetadata(metaData);
let imageOrientationPatient = extractOrientationFromMetadata(metaData);
let imagePositionPatient = extractPositionFromMetadata(metaData);
const pixelSpacing = getNumberValues(metaData['00280030'], 2);

let columnPixelSpacing = null;
let rowPixelSpacing = null;
let rowCosines = null;
let columnCosines = null;

let usingDefaultValues = false;
if (pixelSpacing) {
rowPixelSpacing = pixelSpacing[0];
columnPixelSpacing = pixelSpacing[1];
} else {
usingDefaultValues = true;
rowPixelSpacing = 1;
columnPixelSpacing = 1;
}

if (imageOrientationPatient) {
rowCosines = [
// @ts-expect-error
parseFloat(imageOrientationPatient[0]),
// @ts-expect-error
parseFloat(imageOrientationPatient[1]),
// @ts-expect-error
parseFloat(imageOrientationPatient[2]),
];
columnCosines = [
// @ts-expect-error
parseFloat(imageOrientationPatient[3]),
// @ts-expect-error
parseFloat(imageOrientationPatient[4]),
// @ts-expect-error
parseFloat(imageOrientationPatient[5]),
];
} else {
rowCosines = [1, 0, 0];
columnCosines = [0, 1, 0];
usingDefaultValues = true;
imageOrientationPatient = [...rowCosines, ...columnCosines];
}

if (!imagePositionPatient) {
imagePositionPatient = [0, 0, 0];
usingDefaultValues = true;
}

return {
frameOfReferenceUID: getValue<string>(metaData['00200052']),
rows: getNumberValue(metaData['00280010']),
columns: getNumberValue(metaData['00280011']),
imageOrientationPatient,
rowCosines,
columnCosines,
imagePositionPatient,
sliceThickness: getNumberValue(metaData['00180050']),
sliceLocation: getNumberValue(metaData['00201041']),
pixelSpacing,
rowPixelSpacing,
columnPixelSpacing,
usingDefaultValues,
};
}

if (type === MetadataModules.ULTRASOUND_ENHANCED_REGION) {
return getUSEnhancedRegions(metaData);
}
Expand Down Expand Up @@ -279,13 +208,6 @@ function metaDataProvider(type, imageId) {
};
}

if (type === MetadataModules.SOP_COMMON) {
return {
sopClassUID: getValue<string>(metaData['00080016']),
sopInstanceUID: getValue<string>(metaData['00080018']),
};
}

if (type === MetadataModules.PET_ISOTOPE) {
const radiopharmaceuticalInfo = getValue(metaData['00540016']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
instanceModuleNames,
} from '../../getInstanceModule';
import { getUSEnhancedRegions } from './USHelpers';
import { Modules } from '../../../shared/Tags';

function metaDataProvider(type, imageId) {
const { MetadataModules } = Enums;
Expand Down Expand Up @@ -65,12 +66,16 @@ function metaDataProvider(type, imageId) {
return metadataForDataset(type, imageId, dataSet);
}

const { MetadataModules } = Enums;

export function metadataForDataset(
type,
imageId,
dataSet: dicomParser.DataSet
) {
const { MetadataModules } = Enums;
if (Modules[type]) {
return Modules[type].fromDataset(dataSet);
}

if (type === MetadataModules.GENERAL_STUDY) {
return {
Expand Down Expand Up @@ -139,66 +144,6 @@ export function metadataForDataset(
};
}

if (type === MetadataModules.IMAGE_PLANE) {
const imageOrientationPatient = extractOrientationFromDataset(dataSet);
const imagePositionPatient = extractPositionFromDataset(dataSet);
const pixelSpacing = extractSpacingFromDataset(dataSet);
const sliceThickness = extractSliceThicknessFromDataset(dataSet);

let columnPixelSpacing = null;

let rowPixelSpacing = null;

let usingDefaultValues = false;
if (pixelSpacing) {
rowPixelSpacing = pixelSpacing[0];
columnPixelSpacing = pixelSpacing[1];
} else {
usingDefaultValues = true;
rowPixelSpacing = 1;
columnPixelSpacing = 1;
}

let rowCosines = null;

let columnCosines = null;

if (imageOrientationPatient) {
rowCosines = [
// @ts-expect-error
parseFloat(imageOrientationPatient[0]),
// @ts-expect-error
parseFloat(imageOrientationPatient[1]),
// @ts-expect-error
parseFloat(imageOrientationPatient[2]),
];
columnCosines = [
// @ts-expect-error
parseFloat(imageOrientationPatient[3]),
// @ts-expect-error
parseFloat(imageOrientationPatient[4]),
// @ts-expect-error
parseFloat(imageOrientationPatient[5]),
];
}

return {
frameOfReferenceUID: dataSet.string('x00200052'),
rows: dataSet.uint16('x00280010'),
columns: dataSet.uint16('x00280011'),
imageOrientationPatient,
rowCosines,
columnCosines,
imagePositionPatient,
sliceThickness,
sliceLocation: dataSet.floatString('x00201041'),
pixelSpacing,
rowPixelSpacing,
columnPixelSpacing,
usingDefaultValues,
};
}

if (type === MetadataModules.CINE) {
return {
frameTime: dataSet.floatString('x00181063'),
Expand Down Expand Up @@ -237,10 +182,7 @@ export function metadataForDataset(
}

if (type === MetadataModules.SOP_COMMON) {
return {
sopClassUID: dataSet.string('x00080016'),
sopInstanceUID: dataSet.string('x00080018'),
};
return Modules[MetadataModules.SOP_COMMON].fromDataset(dataSet);
}

if (type === MetadataModules.PET_ISOTOPE) {
Expand Down
3 changes: 3 additions & 0 deletions packages/dicomImageLoader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as constants from './constants';
import type * as Types from './types';
import { decodeImageFrame } from './decodeImageFrameWorker';
import { initializers } from './shared/decoders';
import * as utilities from './shared';

const cornerstoneDICOMImageLoader = {
constants,
Expand All @@ -33,6 +34,7 @@ const cornerstoneDICOMImageLoader = {
wadouri,
wadors,
init,
utilities,
convertColorSpace,
createImage,
decodeJPEGBaseline8BitColor,
Expand All @@ -55,6 +57,7 @@ export {
convertPALETTECOLOR,
wadouri,
wadors,
utilities,
init,
convertColorSpace,
createImage,
Expand Down
Loading
Loading