BUG: Fail gracefully when grayvalue <= 0 #602
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
"0" is an invalid value for gray level and causes an index error in the calculation of texture matrices (e.g. for GLSZM, correct index in matrix is calculated as (i, j) = (grayvalue - 1, region size), which in case of gray value 0 results in index -1, which is invalid).
In some case, this resulted in a graceful error where an IndexError is raised, but this is most likely because the datatype used for the index (
size_t
) does not allow for negative indices on some systems and therefore results in an overflow, which on the subsequent check is then indeed larger than the maximum allowed index (which is checked). In other cases,size_t
datatype does allow for negative values and therefore passes the maximum index check and subsequently fails with a Process terminated.Add an additional check to ensure the gray level is > 0, otherwise, fail the C Extension gracefully. Non-gray level properties (i.e. run length, zone size, dependence counts) are calculated in the C extension and ensured to be >= 0.