algorithm to find HSV value