Skip to content

Commit

Permalink
Add unit to draw quantification, fixes #1489
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Sep 5, 2023
1 parent 9592c8a commit dccddce
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 29 deletions.
24 changes: 16 additions & 8 deletions src/image/imageFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,22 @@ export class ImageFactory {
}

// PET SUV
let intensityFactor = 1;
let isPetWithSuv = false;
if (modality.value[0] === 'PT') {
const warn = canGetSuvFactor(dataElements);
if (warn.length === 0) {
intensityFactor = getSuvFactor(dataElements);
logger.info('Applying PET SUV calibration: ' + intensityFactor);
slope *= intensityFactor;
intercept *= intensityFactor;
isPetWithSuv = true;
} else {
logger.warn(warn);
}
}
let intensityFactor = 1;
if (isPetWithSuv) {
intensityFactor = getSuvFactor(dataElements);
logger.info('Applying PET SUV calibration: ' + intensityFactor);
slope *= intensityFactor;
intercept *= intensityFactor;
}
const rsi = new RescaleSlopeAndIntercept(slope, intercept);
image.setRescaleSlopeAndIntercept(rsi);

Expand All @@ -238,9 +242,13 @@ export class ImageFactory {
// PixelRepresentation -> is signed
meta.IsSigned = meta.PixelRepresentation === 1;
// local pixel unit
const pixelUnit = getPixelUnit(dataElements);
if (typeof pixelUnit !== 'undefined') {
meta.pixelUnit = pixelUnit;
if (isPetWithSuv) {
meta.pixelUnit = 'SUV';
} else {
const pixelUnit = getPixelUnit(dataElements);
if (typeof pixelUnit !== 'undefined') {
meta.pixelUnit = pixelUnit;
}
}
// FrameOfReferenceUID (optional)
const frameOfReferenceUID = dataElements['00200052'];
Expand Down
15 changes: 8 additions & 7 deletions src/math/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,20 @@ export class Circle {
const regions = this.getRound();
if (regions.length !== 0) {
const values = viewController.getImageVariableRegionValues(regions);
const unit = viewController.getPixelUnit();
const quantif = getStats(values, flags);
quant.min = {value: quantif.min, unit: ''};
quant.max = {value: quantif.max, unit: ''};
quant.mean = {value: quantif.mean, unit: ''};
quant.stdDev = {value: quantif.stdDev, unit: ''};
quant.min = {value: quantif.min, unit: unit};
quant.max = {value: quantif.max, unit: unit};
quant.mean = {value: quantif.mean, unit: unit};
quant.stdDev = {value: quantif.stdDev, unit: unit};
if (typeof quantif.median !== 'undefined') {
quant.median = {value: quantif.median, unit: ''};
quant.median = {value: quantif.median, unit: unit};
}
if (typeof quantif.p25 !== 'undefined') {
quant.p25 = {value: quantif.p25, unit: ''};
quant.p25 = {value: quantif.p25, unit: unit};
}
if (typeof quantif.p75 !== 'undefined') {
quant.p75 = {value: quantif.p75, unit: ''};
quant.p75 = {value: quantif.p75, unit: unit};
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/math/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,20 @@ export class Ellipse {
const regions = this.getRound();
if (regions.length !== 0) {
const values = viewController.getImageVariableRegionValues(regions);
const unit = viewController.getPixelUnit();
const quantif = getStats(values, flags);
quant.min = {value: quantif.min, unit: ''};
quant.max = {value: quantif.max, unit: ''};
quant.mean = {value: quantif.mean, unit: ''};
quant.stdDev = {value: quantif.stdDev, unit: ''};
quant.min = {value: quantif.min, unit: unit};
quant.max = {value: quantif.max, unit: unit};
quant.mean = {value: quantif.mean, unit: unit};
quant.stdDev = {value: quantif.stdDev, unit: unit};
if (typeof quantif.median !== 'undefined') {
quant.median = {value: quantif.median, unit: ''};
quant.median = {value: quantif.median, unit: unit};
}
if (typeof quantif.p25 !== 'undefined') {
quant.p25 = {value: quantif.p25, unit: ''};
quant.p25 = {value: quantif.p25, unit: unit};
}
if (typeof quantif.p75 !== 'undefined') {
quant.p75 = {value: quantif.p75, unit: ''};
quant.p75 = {value: quantif.p75, unit: unit};
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/math/rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,20 @@ export class Rectangle {
if (viewController.canQuantifyImage()) {
const round = this.getRound();
const values = viewController.getImageRegionValues(round.min, round.max);
const unit = viewController.getPixelUnit();
const quantif = getStats(values, flags);
quant.min = {value: quantif.min, unit: ''};
quant.max = {value: quantif.max, unit: ''};
quant.mean = {value: quantif.mean, unit: ''};
quant.stdDev = {value: quantif.stdDev, unit: ''};
quant.min = {value: quantif.min, unit: unit};
quant.max = {value: quantif.max, unit: unit};
quant.mean = {value: quantif.mean, unit: unit};
quant.stdDev = {value: quantif.stdDev, unit: unit};
if (typeof quantif.median !== 'undefined') {
quant.median = {value: quantif.median, unit: ''};
quant.median = {value: quantif.median, unit: unit};
}
if (typeof quantif.p25 !== 'undefined') {
quant.p25 = {value: quantif.p25, unit: ''};
quant.p25 = {value: quantif.p25, unit: unit};
}
if (typeof quantif.p75 !== 'undefined') {
quant.p75 = {value: quantif.p75, unit: ''};
quant.p75 = {value: quantif.p75, unit: unit};
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/math/circle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ QUnit.test('Test Circle quantify.', function (assert) {
},
getImageVariableRegionValues: function () {
return [0, 1, 1, 0, 0, 1, 1, 0];
},
getPixelUnit: function () {
return '';
}
};
const theoQuant0 = {
Expand Down
3 changes: 3 additions & 0 deletions tests/math/ellipse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ QUnit.test('Test Ellipse quantify.', function (assert) {
},
getImageVariableRegionValues: function () {
return [0, 1, 1, 0, 0, 1, 1, 0];
},
getPixelUnit: function () {
return '';
}
};
const theoQuant0 = {
Expand Down
3 changes: 3 additions & 0 deletions tests/math/rectangle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ QUnit.test('Test Rectangle quantify.', function (assert) {
},
getImageRegionValues: function () {
return [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0];
},
getPixelUnit: function () {
return '';
}
};
const theoQuant0 = {
Expand Down

0 comments on commit dccddce

Please sign in to comment.