Metadata can be directly compared using:
def tiff = path('image.tiff').tiff
def reference = path('reference.tiff').tiff
assert tiff.meta == reference.metaThis will check every metadata field in every directory of the TIFF files for equality.
The height and width of TIFF files can be compared using the meta.getDimensions() function:
def tiff = path('image.tiff').tiff
def reference = path('reference.tiff').tiff
def dim = tiff.meta.getDimensions()
def referenceDim = reference.meta.getDimensions()
assert dim == referenceDimThe number of metadata fields in each directory of a TIFF file can be checked using the meta.getFieldCounts() function:
def tiff = path('image.tiff').tiff
assert tiff.meta.getFieldCounts()[0] == 10Note that meta.getFieldCounts() returns a list, where each element corresponds to the directory at the same position.
The names of metadata fields in each directory of a TIFF file can be checked using the meta.getFieldNames() function:
def tiff = path('image.tiff').tiff
def reference = path('reference.tiff').tiff
def fields = tiff.meta.getFieldNames()
def referenceFields = reference.meta.getFieldNames()
assert fields == referenceFields
assert fields[0].contains('Compression')
Note that meta.getFieldNames() returns a list, where each element corresponds to the directory at the same position.
Individual (lists of) metadata fields in each directory of a TIFF file can be compared using the meta.getFields() function:
def tiff = path('image.tiff').tiff
def reference = path('reference.tiff').tiff
def fields = tiff.meta.getFields(['ImageWidth', 'PlanarConfiguration', 'Compression'])
def referenceFields = reference.meta.getFields(['ImageWidth', 'PlanarConfiguration', 'Compression'])
assert fields == referenceFieldsNote that meta.getFields() returns a List of Maps.
Each index in the list corresponds to a directory in the TIFF file.
The maps assign the field name to the corresponding value.
The function meta.getFields() also accepts a single field as a String and may be called without any parameters to compare every metadata field.
Bitmaps can be directly compared using:
def tiff = path('image.tiff').tiff
def reference = path('reference.tiff').tiff
assert tiff.bitmaps == reference.bitmapsA comparison of bitmaps, where a certain percentage of entries must be equal, can be performed using the bitmaps.matchesWithTolerance() function:
def tiff = path('image.tiff').tiff
def reference = path('reference.tiff').tiff
assert tiff.bitmaps.matchesWithTolerance(reference.bitmaps, 80)In this example the TIFF files image.tiff and reference.tiff are compared and 80% of bitmap entries have to match.
The values of bitmaps can be compared using md5 checksums using the bitmaps.md5() function:
def tiff = path('image.tiff').tiff
def reference = path('reference.tiff').tiff
def md5Sum = tiff.bitmaps.md5()
def referenceMd5Sum = reference.bitmaps.md5()
assert md5Sum == referenceMd5SumThis is particularly useful with snapshots:
def tiff = path('image.tiff').tiff
def md5 = tiff.bitmaps.md5()
assert snapshot(md5).match()