35 helpCtx = TestHelper.getInstance().getHelperContext()
37 modImgLoad = helpCtx.module(
"iHSImgLoad")
38 modImgHash = helpCtx.module(
"iHSImageHash")
40 hashSelectorField = modImgHash.field(
'hashSelector')
41 if hashMethod
not in hashSelectorField.items():
42 raise Exception(
"Hash method %s unknown. Valid values are: %s" % (hashMethod,
', '.join(hashSelectorField.items())))
43 hashSelectorField.value = hashMethod
45 encoderSelectorField = modImgHash.field(
'encoderSelector')
46 if encoder
not in encoderSelectorField.items():
47 raise Exception(
"Encoder %s unknown. Valid values are: %s" % (encoder,
', '.join(encoderSelectorField.items())))
48 encoderSelectorField.value = encoder
51 modImgLoad.field(
'filename').value = fileName
52 if not modImgHash.field(
'hashValid').value:
53 Logging_error(
"Failed to create hash of image (%s)" % (fileName))
55 result = modImgHash.field(
'hash').value
56 modImgLoad.field(
'close').touch()
69def getVoxelValue (outFieldName, position, coordinateType="Voxel", useStoredValue=False):
70 testCtx = Base_getTestCaseContext()
71 helpCtx = TestHelper.getInstance().getHelperContext()
75 outField = testCtx.field(outFieldName)
77 module = helpCtx.module(
"GetVoxelValue")
78 module.field(
"input0").connectFrom(outField)
79 module.field(
"coordinateType").value = coordinateType
80 module.field(
"position").value = position
81 module.field(
"updateButton").touch()
82 if not useStoredValue:
83 result = (module.field(
"outputStringValue").value, module.field(
"outputValue").value)
85 result = (module.field(
"storedStringValue").value, module.field(
"storedValue").value)
86 if not outField
or not module.field(
"valid").value:
87 Logging_error(
"Failed to retrieve voxel value.")
94def __imageCompare (compareModule, outFieldA, outFieldB):
95 testCtx = Base_getTestCaseContext()
96 helpCtx = TestHelper.getInstance().getHelperContext()
98 fieldA = testCtx.field(outFieldA)
99 fieldB = testCtx.field(outFieldB)
100 if fieldA
and fieldB:
101 module = helpCtx.module(compareModule)
102 module.field(
"input0").connectFrom(fieldA)
103 module.field(
"input1").connectFrom(fieldB)
104 module.field(
"compare").touch()
105 if module.field(
"testPassed").value:
106 Logging_info(
"Image Compare with (%s): No differences found" % (compareModule))
108 Logging_info(
"Image Compare with (%s): differences found" % (compareModule))
109 return module.field(
"testPassed").value
115 return __imageCompare(
"ImageCompareDefault", outFieldA, outFieldB)
122 return __imageCompare(
"ImageCompareProperties", outFieldA, outFieldB)
128 return __imageCompare(
"ImageCompareData", outFieldA, outFieldB)
134 return __imageCompare(
"ImageCompareAllProps", outFieldA, outFieldB)
139 """! Returns the true min/max range of the image data, which is therefore scanned entirely using a MinMaxScan module.
140 @param outFieldName String: Name of the output image field
141 @return tuple(Number, Number): Returns a tuple (trueMinimumValue, trueMaximumValue) or (None, None) if the image could not be scanned
143 testCtx = Base_getTestCaseContext()
144 helpCtx = TestHelper.getInstance().getHelperContext()
147 outField = testCtx.field(outFieldName)
148 if outField
and outField.isValid():
149 module = helpCtx.module(
"MinMaxScan")
150 module.field(
"input0").connectFrom(testCtx.field(outFieldName))
151 module.field(
"update").touch()
152 if module.field(
"upToDate").value:
153 trueMin = module.field(
"trueMinValue").value
154 trueMax = module.field(
"trueMaxValue").value
155 return trueMin, trueMax
159def verifyMinMaxPropertyValues(outFieldName, expectedMin = None, expectedMax = None, requireExactMin = False, requireExactMax = False, logOnSuccess = True):
160 """! Verifies the min/max image property values. By default (none of the optional arguments
161 provided) the functions just checks if the min/max range specified by the image properties include the actual
162 min/max range of the image data, which is therefore scanned. Note that this check is always done, since ML
163 images always need to fulfill the condition. In addition, it is possible to check against expected values, or
164 to require exact matches of the range boundaries (using the expected values, if provided, and the actual
165 values otherwise). Logs an error if the output image is valid and any of the checks fail.
166 @outFieldName String: Name of the output image field to perform the check on.
167 @param expectedMin Number: If given, the minimum value image property is compared against expectedMin
168 @param expectedMax Number: If given, the maximum value image property is compared against expectedMax
169 @param requireExactMin Bool: If given, the minimum value image property must be identical to expectedMin (if given) or the actual image minimum (otherwise)
170 @param requireExactMax Bool: If given, the maximum value image property must be identical to expectedMax (if given) or the actual image maximum (otherwise)
171 @param logOnSuccess Bool: If enabled, provide success message
173 errorOccurred =
False
174 outField = Base_getTestCaseContext().field( outFieldName )
175 comparisonErrorComment =
"Min/max value error for field %s." % outFieldName
176 if outField.isValid():
178 if trueMin
is None or trueMax
is None:
180 Logging_error(
"Image.verifyMinMaxPropertyValues(): Unexpected error scanning the image at field %s!" % outFieldName)
182 if expectedMin
is None:
183 expectedMin = outField.minValue()
184 if expectedMax
is None:
185 expectedMax = outField.maxValue()
187 if not Base_compareFloatEqual(trueMin, expectedMin, comparisonErrorComment):
190 if not Base_compareFloatLessThanOrEqual(expectedMin, trueMin, comparisonErrorComment):
193 if not Base_compareFloatEqual(trueMax, expectedMax, comparisonErrorComment):
196 if not Base_compareFloatLessThanOrEqual(trueMax, expectedMax, comparisonErrorComment):
199 if not errorOccurred
and logOnSuccess:
200 Logging_info(
"Image.verifyMinMaxPropertyValues(%s): SUCCESS" % outFieldName )
205from .Logging
import error
as Logging_error, info
as Logging_info
206from .Base
import getTestCaseContext
as Base_getTestCaseContext, \
207 compareFloatEqual
as Base_compareFloatEqual, \
208 compareFloatLessThanOrEqual
as Base_compareFloatLessThanOrEqual
compareImagesProperties(outFieldA, outFieldB)
Compare just the properties of the two given images (excluding page extent, the extension properties,...
getTrueMinMaxValues(outFieldName)
Returns the true min/max range of the image data, which is therefore scanned entirely using a MinMaxS...
compareImagesAllProps(outFieldA, outFieldB)
Compare the two given images.
getVoxelValue(outFieldName, position, coordinateType="Voxel", useStoredValue=False)
Get the voxel value of the given field at the given position.
compareImages(outFieldA, outFieldB)
Compare the two given images (excluding the extention properties).
compareImagesData(outFieldA, outFieldB)
Compare the two given images (only verifying data).
calculateHashFromImage(fileName, hashMethod='SHA256', encoder='Hex')
Calculate the hash of the given image.
verifyMinMaxPropertyValues(outFieldName, expectedMin=None, expectedMax=None, requireExactMin=False, requireExactMax=False, logOnSuccess=True)
Verifies the min/max image property values.