import math


def get_region_characteristics(region_data):
    """
    Calculate the characteristics of a region given its moments.

    Arguments:
        moments {dictionary} -- Contains all the ordinary moments.

    Returns:
        Dictionary -- Contains:
            x_center: x coordinate of the centroid.
            y_center: y coordinate of the controid.
            theta: The orientation of the region.
            phi_1: First Hu moment.
            phi_2: Second Hu moment.
    """

    # Location of the region.
    x_center = int(region_data["10"] / region_data["00"])
    y_center = int(region_data["01"] / region_data["00"])

    # Centralized moments.
    mu_11 = region_data["11"] - y_center * region_data["10"]
    mu_20 = region_data["20"] - x_center * region_data["10"]
    mu_02 = region_data["02"] - y_center * region_data["01"]

    # Orientation.
    theta = math.atan2(2 * mu_11, mu_20 - mu_02) / 2

    # Normalized moments.
    nu_11 = mu_11 / region_data["00"] ** 2
    nu_20 = mu_20 / region_data["00"] ** 2
    nu_02 = mu_02 / region_data["00"] ** 2

    # Hu moments.
    phi_1 = nu_20 + nu_02
    phi_2 = ((nu_20 - nu_02) ** 2) + (4 * (nu_11 ** 2))

    return {
        "x_center": x_center,
        "y_center": y_center,
        "theta": theta,
        "phi_1": phi_1,
        "phi_2": phi_2,
        "width": region_data["max_x"] - region_data["min_x"],
        "height": region_data["max_y"] - region_data["min_y"],
    }