|
| 1 | +import test from 'ava' |
| 2 | +import path from 'path' |
| 3 | + |
| 4 | +import { compareImagesNode } from '../../dist/bundles/compare-images-node.js' |
| 5 | +import { readImageLocalFile } from 'itk-wasm' |
| 6 | + |
| 7 | +const inputPathPrefix = '../test/data/input/' |
| 8 | + |
| 9 | +test('compareImagesNode produces the expected metrics and difference images for uint8 inputs', async t => { |
| 10 | + const testImageFile = 'cake_easy.png' |
| 11 | + const testImagePath = path.join(inputPathPrefix, testImageFile) |
| 12 | + const testImage = await readImageLocalFile(testImagePath) |
| 13 | + |
| 14 | + const baselineImageFile = 'cake_hard.png' |
| 15 | + const baselineImagePath = path.join(inputPathPrefix, baselineImageFile) |
| 16 | + const baselineImage = await readImageLocalFile(baselineImagePath) |
| 17 | + |
| 18 | + const { metrics, differenceImage, differenceUchar2dImage } = await compareImagesNode(testImage, { baselineImages: [baselineImage,] }) |
| 19 | + |
| 20 | + t.is(metrics.almostEqual, false) |
| 21 | + t.is(metrics.numberOfPixelsWithDifferences, 9915) |
| 22 | + t.is(metrics.minimumDifference, 1.0) |
| 23 | + t.is(metrics.maximumDifference, 107.0) |
| 24 | + t.is(metrics.totalDifference, 337334.0) |
| 25 | + t.is(metrics.meanDifference, 34.02259203227433) |
| 26 | + |
| 27 | + t.is(differenceImage.imageType.componentType, 'float64') |
| 28 | + t.is(differenceUchar2dImage.imageType.componentType, 'uint8') |
| 29 | +}) |
| 30 | + |
| 31 | +test('compareImagesNode produces the expected metrics and difference images for rgb inputs', async t => { |
| 32 | + const testImageFile = 'apple.jpg' |
| 33 | + const testImagePath = path.join(inputPathPrefix, testImageFile) |
| 34 | + const testImage = await readImageLocalFile(testImagePath) |
| 35 | + |
| 36 | + const baselineImageFile = 'orange.jpg' |
| 37 | + const baselineImagePath = path.join(inputPathPrefix, baselineImageFile) |
| 38 | + const baselineImage = await readImageLocalFile(baselineImagePath) |
| 39 | + |
| 40 | + const { metrics, differenceImage, differenceUchar2dImage } = await compareImagesNode(testImage, { baselineImages: [baselineImage,] }) |
| 41 | + |
| 42 | + t.is(metrics.almostEqual, false) |
| 43 | + t.is(metrics.numberOfPixelsWithDifferences, 26477) |
| 44 | + t.is(metrics.minimumDifference, 0.002273026683894841) |
| 45 | + t.is(metrics.maximumDifference, 312.2511648746159) |
| 46 | + t.is(metrics.totalDifference, 3121703.1639738297) |
| 47 | + t.is(metrics.meanDifference, 117.90244982338746) |
| 48 | + |
| 49 | + t.is(differenceImage.imageType.componentType, 'float64') |
| 50 | + t.is(differenceUchar2dImage.imageType.componentType, 'uint8') |
| 51 | +}) |
0 commit comments