Skip to content

Conversation

@YaoTingYao
Copy link
Member

@YaoTingYao YaoTingYao commented Mar 26, 2024

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:

  1. If data type is byte or integer and min is 0 and max is 1, it returns True.

  2. 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.

  3. For any other scenario, it returns False.

image

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:

1.	If data type is byte or integer and min is 0 and max is 1, it returns 
True.

2.	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.

3.	For any other scenario, it returns False.
@YaoTingYao YaoTingYao requested a review from tawoodard March 26, 2024 21:53
@YaoTingYao
Copy link
Member Author

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!

Copy link
Member

@tawoodard tawoodard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Yao-Ting,
The changes look good except I'm confused about why the new functions are in there 8 times. (lines 214-268; lines 579-634; 821-876; 1133-1189; 1454-1509; 1716-1771; 2045-2100; 2351-2406; 2616-2671) Repeating code makes it harder to maintain. Perhaps I am missing something (the reason why it needs to be repeated or perhaps there are slight variations that I am not noticing.)

If the functions are inside of other functions, perhaps they could be pulled out to the main level. Or perhaps they need to be where they are. If so, let me know and I'll approve it.

Tammy

@tawoodard
Copy link
Member

I thought about it & realized we can optimize later for repeated code blocks. Sorry for the delay. I'll confirm the merge now.

@tawoodard tawoodard merged commit 56b9c01 into main Mar 27, 2024
@YaoTingYao
Copy link
Member Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants