Added an image transformation function that transforms individual pixels according to a specific function.
Refactored Threshold to utilize this function.