Skip to content

Commit

Permalink
FIXED PixelSPacing for US case (#321)
Browse files Browse the repository at this point in the history
* FIXED PixelSPacing for US case

TODO: check why build is so slow

* Update docs

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent d6831d3 commit 2355f29
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 64 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

## Dicom Image Toolkit for CornerstoneJS

### Current version: 2.4.6
### Current version: 2.4.7

### Latest Published Release: 2.4.6
### Latest Published Release: 2.4.7

This library provides common DICOM functionalities to be used in web-applications: it's wrapper that simplifies the use of cornerstone-js environment.

Expand Down
2 changes: 1 addition & 1 deletion dist/larvitar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/larvitar.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/documentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ <h3> </h3>
<h1 id="larvitar">Larvitar</h1>
<p><a href="https://github.com/dvisionlab/Larvitar"><img src="https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&amp;prefix=%E2%89%A5&amp;suffix=%25&amp;query=$.typeCoverage.atLeast&amp;uri=https%3A%2F%2Fraw.githubusercontent.com%2Fplantain-00%2Ftype-coverage%2Fmaster%2Fpackage.json" alt="type-coverage"></a></p>
<h2 id="dicom-image-toolkit-for-cornerstonejs">Dicom Image Toolkit for CornerstoneJS</h2>
<h3 id="current-version%3A-2.4.6">Current version: 2.4.6</h3>
<h3 id="latest-published-release%3A-2.4.6">Latest Published Release: 2.4.6</h3>
<h3 id="current-version%3A-2.4.7">Current version: 2.4.7</h3>
<h3 id="latest-published-release%3A-2.4.7">Latest Published Release: 2.4.7</h3>
<p>This library provides common DICOM functionalities to be used in web-applications: it's wrapper that simplifies the use of cornerstone-js environment.</p>
<h2 id="features%3A">Features:</h2>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/larvitar.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion imaging/imageParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,16 @@ const parseFile = function (file: File) {
? metadata["x00080018"]
: metadata["x0020000e"];
let seriesInstanceUID = metadata["x0020000e"];
let pixelSpacing = metadata["x00280030"];
let pixelSpacing = metadata.x00280030
? metadata.x00280030
: metadata.x00080060 === "US" &&
metadata["x00186011"]![0].x0018602e != undefined &&
metadata["x00186011"]![0].x0018602c != undefined
? ([
metadata["x00186011"]![0].x0018602e * 10, //so that from cm goes to mm
metadata["x00186011"]![0].x0018602c * 10
] as [number, number])
: metadata.x00280030;
let imageOrientation = metadata["x00200037"];
let imagePosition = metadata["x00200032"];
let sliceThickness = metadata["x00180050"];
Expand Down
11 changes: 10 additions & 1 deletion imaging/imageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,16 @@ export const getReslicedMetadata = function (
metadata.cols = metadata.x00280011;
metadata.imageOrientation = metadata.x00200037;
metadata.imagePosition = metadata.x00200032;
metadata.pixelSpacing = metadata.x00280030;
metadata.pixelSpacing = metadata.x00280030
? metadata.x00280030
: metadata.x00080060 === "US" &&
metadata["x00186011"]![0].x0018602e != undefined &&
metadata["x00186011"]![0].x0018602c != undefined
? ([
metadata["x00186011"]![0].x0018602e * 10, //so that from cm goes to mm
metadata["x00186011"]![0].x0018602c * 10
] as [number, number])
: metadata.x00280030;
metadata.instanceUID = metadata.x00080018;
metadata.minPixelValue = metadata.x00280106;
metadata.maxPixelValue = metadata.x00280107;
Expand Down
19 changes: 12 additions & 7 deletions imaging/loaders/multiframeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,16 @@ let createCustomImage = function (
// before creating the custom image object (like the multiframe case).
setPixelDataType(imageFrame);

let pixelSpacing = metadata.x00280030 ? metadata.x00280030 : 1.0;
let pixelSpacing = metadata.x00280030
? metadata.x00280030
: metadata.x00080060 === "US" &&
metadata["x00186011"]![0].x0018602e != undefined &&
metadata["x00186011"]![0].x0018602c != undefined
? ([
metadata["x00186011"]![0].x0018602e * 10, //so that from cm goes to mm
metadata["x00186011"]![0].x0018602c * 10
] as [number, number])
: metadata.x00280030;
let rescaleIntercept = metadata.x00281052;
let rescaleSlope = metadata.x00281053;
let windowCenter = metadata.x00281050;
Expand All @@ -309,9 +318,7 @@ let createCustomImage = function (
color: cornerstoneDICOMImageLoader.isColorImage(
imageFrame.photometricInterpretation
),
columnPixelSpacing: (pixelSpacing as number[])[1]
? (pixelSpacing as number[])[1]
: (pixelSpacing as number), // check for specific spacing value
columnPixelSpacing: (pixelSpacing as number[])[1],
columns: imageFrame.columns,
data: dataSet ? dataSet : undefined,
height: imageFrame.rows,
Expand All @@ -323,9 +330,7 @@ let createCustomImage = function (
minPixelValue: imageFrame.smallestPixelValue,
maxPixelValue: imageFrame.largestPixelValue,
render: undefined, // set below
rowPixelSpacing: (pixelSpacing as number[])[0]
? (pixelSpacing as number[])[0]
: (pixelSpacing as number), // check for specific spacing value
rowPixelSpacing: (pixelSpacing as number[])[0],
rows: imageFrame.rows,
sizeInBytes: getSizeInBytes(),
slope: (rescaleSlope as number) ? (rescaleSlope as number) : 1,
Expand Down
11 changes: 10 additions & 1 deletion imaging/loaders/nrrdLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,16 @@ let createCustomImage = function (
// before creating the custom image object (like the multiframe case).
imageFrame.pixelData = pixelData;

let pixelSpacing = metadata.x00280030;
let pixelSpacing = metadata.x00280030
? metadata.x00280030
: metadata.x00080060 === "US" &&
metadata["x00186011"]![0].x0018602e != undefined &&
metadata["x00186011"]![0].x0018602c != undefined
? ([
metadata["x00186011"]![0].x0018602e * 10, //so that from cm goes to mm
metadata["x00186011"]![0].x0018602c * 10
] as [number, number])
: metadata.x00280030;
let rescaleIntercept = metadata.x00281052;
let rescaleSlope = metadata.x00281053;
let windowCenter = metadata.x00281050;
Expand Down
11 changes: 10 additions & 1 deletion imaging/loaders/resliceLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ let createCustomImage = function (
// before creating the custom image object (like the multiframe case).
imageFrame.pixelData = pixelData;

let pixelSpacing = metadata.x00280030;
let pixelSpacing = metadata.x00280030
? metadata.x00280030
: metadata.x00080060 === "US" &&
metadata["x00186011"]![0].x0018602e != undefined &&
metadata["x00186011"]![0].x0018602c != undefined
? ([
metadata["x00186011"]![0].x0018602e * 10, //so that from cm goes to mm
metadata["x00186011"]![0].x0018602c * 10
] as [number, number])
: metadata.x00280030;
let rescaleIntercept = metadata.x00281052;
let rescaleSlope = metadata.x00281053;
let windowCenter = metadata.x00281050;
Expand Down
14 changes: 8 additions & 6 deletions imaging/tools/custom/EllipticalRoiUSTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
const context: CanvasRenderingContext2D = getNewContext(
eventData.canvasContext.canvas
);
const { rowPixelSpacing, colPixelSpacing } = getPixelSpacing(image);

let { rowPixelSpacing, colPixelSpacing } = getPixelSpacing(image);
if (this.modality === "US") {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}
const hasPixelSpacing: boolean =
rowPixelSpacing != undefined &&
rowPixelSpacing != 0 &&
Expand Down Expand Up @@ -478,10 +481,9 @@ function _createTextBoxContent(
*/
function _formatArea(modality: string, area: number, hasPixelSpacing: boolean) {
// This uses Char code 178 for a superscript 2
const suffix =
!hasPixelSpacing || modality === "US"
? ` px${String.fromCharCode(178)}`
: ` mm${String.fromCharCode(178)}`;
const suffix = !hasPixelSpacing
? ` px${String.fromCharCode(178)}`
: ` mm${String.fromCharCode(178)}`;

return `Area: ${numbersWithCommas(area.toFixed(2))}${suffix}`;
}
Expand Down
15 changes: 11 additions & 4 deletions imaging/tools/custom/FreehandRoiUSTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ export default class FreehandRoiTool extends BaseAnnotationTool {

// Retrieve the pixel spacing values, and if they are not
// Real non-zero values, set them to 1
const { colPixelSpacing, rowPixelSpacing } = getPixelSpacing(image);
let { colPixelSpacing, rowPixelSpacing } = getPixelSpacing(image);
if (this.modality === "US") {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}
const scaling = (colPixelSpacing || 1) * (rowPixelSpacing || 1);

const area = freehandArea(data.handles.points, scaling);
Expand Down Expand Up @@ -537,14 +541,17 @@ export default class FreehandRoiTool extends BaseAnnotationTool {
// This uses Char code 178 for a superscript 2
let suffix = ` mm${String.fromCharCode(178)}`;

const { rowPixelSpacing, colPixelSpacing } = getPixelSpacing(image);
let { rowPixelSpacing, colPixelSpacing } = getPixelSpacing(image);
if (this.modality === "US") {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}

if (
rowPixelSpacing === undefined ||
rowPixelSpacing === 0 ||
colPixelSpacing === undefined ||
colPixelSpacing === 0 ||
modality === "US"
colPixelSpacing === 0
) {
suffix = ` pixels${String.fromCharCode(178)}`;
}
Expand Down
41 changes: 11 additions & 30 deletions imaging/tools/custom/LengthUSTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,6 @@ export default class LengthTool extends BaseAnnotationTool {
this.modality = viewport.modality;
}

/*
if(this.modality===undefined)
{let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
eventData.image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
console.log(getLarvitarImageTracker());
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager() as LarvitarManager;
if (manager && seriesId) {
let series = manager[seriesId] as Series;
this.modality =
series.instances[eventData.image.imageId].metadata["x00080060"];
} else {
const seriesModule: { modality: string } =
external.cornerstone.metaData.get(
"generalSeriesModule",
eventData.image.imageId
) || {};
if (seriesModule.modality) {
this.modality = seriesModule.modality;
}
}}*/

if (!goodEventData) {
console.error(
`required eventData not supplied to tool ${this.name}'s createNewMeasurement`
Expand Down Expand Up @@ -170,7 +145,11 @@ export default class LengthTool extends BaseAnnotationTool {
element: Element,
data: MeasurementData
) {
const { rowPixelSpacing, colPixelSpacing } = getPixelSpacing(image);
let { rowPixelSpacing, colPixelSpacing } = getPixelSpacing(image);
if (this.modality === "US") {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}

// Set rowPixelSpacing and columnPixelSpacing to 1 if they are undefined (or zero)
const dx =
Expand Down Expand Up @@ -206,12 +185,15 @@ export default class LengthTool extends BaseAnnotationTool {
eventData.canvasContext.canvas
);
const { image, element } = eventData;
const {
let {
rowPixelSpacing,
colPixelSpacing
}: { rowPixelSpacing: number; colPixelSpacing: number } =
getPixelSpacing(image);

if (this.modality === "US") {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}
const lineWidth: number = toolStyle.getToolWidth();
const lineDash: boolean = getModule("globalConfiguration").configuration
.lineDash;
Expand Down Expand Up @@ -332,8 +314,7 @@ export default class LengthTool extends BaseAnnotationTool {
rowPixelSpacing === undefined ||
rowPixelSpacing === 0 ||
colPixelSpacing === undefined ||
colPixelSpacing === 0 ||
modality === "US"
colPixelSpacing === 0
) {
suffix = "pixels";
}
Expand Down
13 changes: 8 additions & 5 deletions imaging/tools/custom/RectangleRoiUSTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ export default class RectangleRoiTool extends BaseAnnotationTool {
const context: CanvasRenderingContext2D = getNewContext(
eventData.canvasContext.canvas
);
const { rowPixelSpacing, colPixelSpacing }: PixelSpacing =
let { rowPixelSpacing, colPixelSpacing }: PixelSpacing =
getPixelSpacing(image);
if (this.modality === "US") {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}

const hasPixelSpacing: boolean =
rowPixelSpacing != undefined &&
Expand Down Expand Up @@ -499,10 +503,9 @@ function _findTextBoxAnchorPoints(
*/
function _formatArea(modality: string, area: number, hasPixelSpacing: boolean) {
// This uses Char code 178 for a superscript 2
const suffix =
!hasPixelSpacing || modality === "US"
? ` px${String.fromCharCode(178)}`
: ` mm${String.fromCharCode(178)}`;
const suffix = !hasPixelSpacing
? ` px${String.fromCharCode(178)}`
: ` mm${String.fromCharCode(178)}`;

return `Area: ${numbersWithCommas(area.toFixed(2))}${suffix}`;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"medical",
"cornerstone"
],
"version": "2.4.6",
"version": "2.4.7",
"description": "typescript library for parsing, loading, rendering and interacting with DICOM images",
"repository": {
"url": "https://github.com/dvisionlab/Larvitar.git",
Expand Down

0 comments on commit 2355f29

Please sign in to comment.