From 626cfcd9e46259ccdaab26bfdb12c190c1e940ca Mon Sep 17 00:00:00 2001 From: Shreeraj Jadhav Date: Thu, 18 Jul 2024 17:05:02 -0400 Subject: [PATCH] WIP: before rebase --- packages/dicom/typescript/package.json | 1 + packages/dicom/typescript/test/node/dcmtk.js | 46 +++++++++----------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/packages/dicom/typescript/package.json b/packages/dicom/typescript/package.json index 3f30f9f50..b592da926 100644 --- a/packages/dicom/typescript/package.json +++ b/packages/dicom/typescript/package.json @@ -44,6 +44,7 @@ "itk-wasm": "workspace:^" }, "devDependencies": { + "@itk-wasm/compare-images": "workspace:*", "@itk-wasm/dicom-build": "workspace:*", "@itk-wasm/image-io": "workspace:*", "@itk-wasm/demo-app": "workspace:*", diff --git a/packages/dicom/typescript/test/node/dcmtk.js b/packages/dicom/typescript/test/node/dcmtk.js index 725243201..4a3467846 100644 --- a/packages/dicom/typescript/test/node/dcmtk.js +++ b/packages/dicom/typescript/test/node/dcmtk.js @@ -12,8 +12,8 @@ import { writeSegmentationNode, } from '../../dist/index-node.js' import { readImageNode, writeImageNode } from '@itk-wasm/image-io' -// import { compareImageToBaseline } from 'cypress/support/compareImageToBaseline.js' -// /home/jadhav/code/itk-wasm/packages/dicom/typescript/cypress/support/compareImageToBaseline.ts +import { compareImagesNode, vectorMagnitudeNode, toScalarDouble } from '@itk-wasm/compare-images' +//import toScalarDouble from '@itk-wasm/compare-images/toScalarDouble'; function arrayEquals(a, b) { return (a.length === b.length && a.every((val, idx) => val === b[idx])) @@ -335,17 +335,23 @@ test('DCMQI write DICOM segmentation object: overlapping labels', async t => { }) */ + /* + async function writeDoubleImage(image, filepath) { + const testImageDouble = await toScalarDouble(vectorMagnitudeNode, image); + await writeImageNode(testImageDouble, filepath); + } + await writeDoubleImage(output.segImage, outputPathPrefix + '/output_makeSeg_double.nrrd'); + */ // dcmqi native tests migrated to TypeScript: +// Path to test data from dcmqi is in its source dir const dcmqi_lib_SOURCE_DIR = '../emscripten-build/_deps/dcmqi_lib-src' -const BASELINE = path.join(dcmqi_lib_SOURCE_DIR, '/data/segmentations') -const JSON_DIR = path.join(dcmqi_lib_SOURCE_DIR, '/doc/examples') test('write-segmentation_makeSEG', async t => { - const inputSegImageFile = path.join(BASELINE,'/liver_seg.nrrd') + const inputSegImageFile = path.join(dcmqi_lib_SOURCE_DIR, 'data/segmentations/liver_seg.nrrd') const inputSegImage = await readImageNode(inputSegImageFile) t.assert(inputSegImage) - const metaInfoFile = path.join(JSON_DIR, '/seg-example.json') + const metaInfoFile = path.join(dcmqi_lib_SOURCE_DIR, 'doc/examples/seg-example.json') const jsonFileBuffer = fs.readFileSync(metaInfoFile) const jsonObject = JSON.parse(jsonFileBuffer) const outputDicomFile = path.join(outputPathPrefix,'liver-seg.dcm') @@ -366,23 +372,13 @@ test('write-segmentation_makeSEG', async t => { const output = await readSegmentationNode(outputDicomFile) t.assert(output.segImage) t.assert(output.metaInfo) - compareImageToBaseline(t, output.segImage, inputSegImage) - - /* - dcmqi_add_test( - NAME ${dcm2itk}_makeNRRD - MODULE_NAME ${MODULE_NAME} - COMMAND $ - --compare ${BASELINE}/liver_seg.nrrd - ${MODULE_TEMP_DIR}/makeNRRD-1.nrrd - ${dcm2itk}Test - --inputDICOM ${MODULE_TEMP_DIR}/liver.dcm - --outputDirectory ${MODULE_TEMP_DIR} - --outputType nrrd - --prefix makeNRRD - TEST_DEPENDS - ${itk2dcm}_makeSEG - ) - */ - + const r1 = await compareImagesNode( + test1, { + baselineImages: [output.segImage], + spatialTolerance: 0.00001, + }) + t.assert(r1) + t.assert(r1 && r1.metrics) + t.assert(r1.metrics.almostEqual) + t.assert(r1.metrics.maximumDifference < 0.01) }) \ No newline at end of file