Closed YaoTingYao closed 7 months ago
Hi @tawoodard, I appreciate your valuable insights on the binary check validation logic. Please review the PR and merge it when you find it convenient? Cheers!
I thought about it & realized we can optimize later for repeated code blocks. Sorry for the delay. I'll confirm the merge now.
Hi @tawoodard, thanks so much for your suggestions on improvements. I initially designed a separate class for each related UI file, which resulted in repetitive functions across the classes. Following your advice, I've relocated the binary check functions into a distinct class and called it by each UI class. It worked smoothly. I will restructure all other repetitive functions and create another PR accordingly. Cheers!
Added a binary map checker to automatically check whether the input data is a binary map or not. After the function returns False, an error message will show up.
A binary map (boolean map) is characterized by a data type of either byte or integer, with minimum and maximum values set to 0 and 1. The only exception is when the data type is real, with minimum and maximum values precisely at 0.0000000 and 1.0000000 and would need to check pixel values.
The validation logic is as follows:
If data type is byte or integer and min is 0 and max is 1, it returns True.
If data type is real and min is 0 and max is 1, it executes a function to check the number of unique values. Because the function only run under this condition and break when the unique value larger than 2, it executed fast in my testing. (1) If the unique number is 2 [0,1], return True. (2) If the number is larger than 2, break and return False.
For any other scenario, it returns False.