38 helpCtx = TestHelper.getInstance().getHelperContext()
40 modImgLoad = helpCtx.module(
"iHSImgLoad")
41 modImgHash = helpCtx.module(
"iHSImageHash")
43 hashSelectorField = modImgHash.field(
"hashSelector")
44 if hashMethod
not in hashSelectorField.items():
46 "Hash method %s unknown. Valid values are: %s" % (hashMethod,
", ".join(hashSelectorField.items()))
48 hashSelectorField.value = hashMethod
50 encoderSelectorField = modImgHash.field(
"encoderSelector")
51 if encoder
not in encoderSelectorField.items():
52 raise Exception(
"Encoder %s unknown. Valid values are: %s" % (encoder,
", ".join(encoderSelectorField.items())))
53 encoderSelectorField.value = encoder
56 modImgLoad.field(
"filename").value = fileName
57 if not modImgHash.field(
"hashValid").value:
58 Logging_error(
"Failed to create hash of image (%s)" % (fileName))
60 result = modImgHash.field(
"hash").value
61 modImgLoad.field(
"close").touch()
77def getVoxelValue(outFieldName, position, coordinateType="Voxel", useStoredValue=False):
78 testCtx = Base_getTestCaseContext()
79 helpCtx = TestHelper.getInstance().getHelperContext()
83 outField = testCtx.field(outFieldName)
85 module = helpCtx.module(
"GetVoxelValue")
86 module.field(
"input0").connectFrom(outField)
87 module.field(
"coordinateType").value = coordinateType
88 module.field(
"position").value = position
89 module.field(
"updateButton").touch()
90 if not useStoredValue:
91 result = (module.field(
"outputStringValue").value, module.field(
"outputValue").value)
93 result = (module.field(
"storedStringValue").value, module.field(
"storedValue").value)
94 if not outField
or not module.field(
"valid").value:
95 Logging_error(
"Failed to retrieve voxel value.")
105def __imageCompare(compareModule, outFieldA, outFieldB):
106 testCtx = Base_getTestCaseContext()
107 helpCtx = TestHelper.getInstance().getHelperContext()
109 fieldA = testCtx.field(outFieldA)
110 fieldB = testCtx.field(outFieldB)
111 if fieldA
and fieldB:
112 module = helpCtx.module(compareModule)
113 module.field(
"input0").connectFrom(fieldA)
114 module.field(
"input1").connectFrom(fieldB)
115 module.field(
"compare").touch()
116 if module.field(
"testPassed").value:
117 Logging_info(
"Image Compare with (%s): No differences found" % (compareModule))
119 Logging_info(
"Image Compare with (%s): differences found" % (compareModule))
120 return module.field(
"testPassed").value
129 return __imageCompare(
"ImageCompareDefault", outFieldA, outFieldB)
139 return __imageCompare(
"ImageCompareProperties", outFieldA, outFieldB)
148 return __imageCompare(
"ImageCompareData", outFieldA, outFieldB)
157 return __imageCompare(
"ImageCompareAllProps", outFieldA, outFieldB)
165 """! Returns the true min/max range of the image data, which is therefore scanned entirely using a MinMaxScan module.
166 @param outFieldName String: Name of the output image field
167 @return tuple(Number, Number): Returns a tuple (trueMinimumValue, trueMaximumValue) or (None, None) if the image could not be scanned
169 testCtx = Base_getTestCaseContext()
170 helpCtx = TestHelper.getInstance().getHelperContext()
173 outField = testCtx.field(outFieldName)
174 if outField
and outField.isValid():
175 module = helpCtx.module(
"MinMaxScan")
176 module.field(
"input0").connectFrom(testCtx.field(outFieldName))
177 module.field(
"update").touch()
178 if module.field(
"upToDate").value:
179 trueMin = module.field(
"trueMinValue").value
180 trueMax = module.field(
"trueMaxValue").value
181 return trueMin, trueMax
189 outFieldName, expectedMin=None, expectedMax=None, requireExactMin=False, requireExactMax=False, logOnSuccess=True
191 """! Verifies the min/max image property values. By default (none of the optional arguments
192 provided) the functions just checks if the min/max range specified by the image properties include the actual
193 min/max range of the image data, which is therefore scanned. Note that this check is always done, since ML
194 images always need to fulfill the condition. In addition, it is possible to check against expected values, or
195 to require exact matches of the range boundaries (using the expected values, if provided, and the actual
196 values otherwise). Logs an error if the output image is valid and any of the checks fail.
197 @outFieldName String: Name of the output image field to perform the check on.
198 @param expectedMin Number: If given, the minimum value image property is compared against expectedMin
199 @param expectedMax Number: If given, the maximum value image property is compared against expectedMax
200 @param requireExactMin Bool: If given, the minimum value image property must be identical to expectedMin (if given) or the actual image minimum (otherwise)
201 @param requireExactMax Bool: If given, the maximum value image property must be identical to expectedMax (if given) or the actual image maximum (otherwise)
202 @param logOnSuccess Bool: If enabled, provide success message
204 errorOccurred =
False
205 outField = Base_getTestCaseContext().field(outFieldName)
206 comparisonErrorComment =
"Min/max value error for field %s." % outFieldName
207 if outField.isValid():
209 if trueMin
is None or trueMax
is None:
212 "Image.verifyMinMaxPropertyValues(): Unexpected error scanning the image at field %s!" % outFieldName
215 if expectedMin
is None:
216 expectedMin = outField.minValue()
217 if expectedMax
is None:
218 expectedMax = outField.maxValue()
220 if not Base_compareFloatEqual(trueMin, expectedMin, comparisonErrorComment):
223 if not Base_compareFloatLessThanOrEqual(expectedMin, trueMin, comparisonErrorComment):
226 if not Base_compareFloatEqual(trueMax, expectedMax, comparisonErrorComment):
229 if not Base_compareFloatLessThanOrEqual(trueMax, expectedMax, comparisonErrorComment):
232 if not errorOccurred
and logOnSuccess:
233 Logging_info(
"Image.verifyMinMaxPropertyValues(%s): SUCCESS" % outFieldName)
239from .Logging
import error
as Logging_error, info
as Logging_info
241 getTestCaseContext
as Base_getTestCaseContext,
242 compareFloatEqual
as Base_compareFloatEqual,
243 compareFloatLessThanOrEqual
as Base_compareFloatLessThanOrEqual,
calculateHashFromImage(fileName, hashMethod="SHA256", encoder="Hex")
Calculate the hash of the given image.
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).
verifyMinMaxPropertyValues(outFieldName, expectedMin=None, expectedMax=None, requireExactMin=False, requireExactMax=False, logOnSuccess=True)
Verifies the min/max image property values.