Project: s41467-025-55825-x | Function: measurement (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Implements the core morphological feature extraction algorithm that computes 103 quantitative metrics from segmented mitochondrial images, including geometric, topological, and statistical features used for function prediction via ensemble learning

**KEY TERMS:** {
  "database": "103-feature dataset for ensemble learning input",
  "database_raw": "39 raw morphological measurements per mitochondrion",
  "directory_path": "path to segmented mitochondrial images",
  "morphological features": "geometric and topological properties of mitochondria"
}

**CONTEXT CODE:**         for input_filepath in image_files:
            crop_image(input_filepath, output_folder)


#
def load_and_skeletonize_image(file_path):
    image = io.imread(file_path)
    binary_image = image > 0
    skeleton = morphology.skeletonize(binary_image)
    return skeleton

def eight_neighbors(x, y, image):
        VIII_neighbors = [image[x, y - 1], image[x - 1, y - 1], image[x - 1, y], image[x - 1, y + 1],
                          image[x, y + 1], image[x + 1, y + 1], image[x + 1, y], image[x + 1, y - 1]]
        return VIII_neighbors

def getSkeletonIntersection(skeleton):

    validIntersection = [[0, 1, 0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1, 0, 0],
                         [0, 1, 0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 0, 1, 0],
                         [0, 1, 0, 0, 1, 0, 0, 1], [1, 0, 1, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0, 1],
                         [0, 1, 0, 1, 0, 0, 0, 1], [0, 1, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 0, 1, 0, 1],
                         [1, 0, 1, 0, 0, 0, 1, 0], [1, 0, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0],
                         [1, 0, 0, 0, 1, 0, 1, 0], [1, 0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 0, 0, 1, 1, 1],
                         [1, 1, 0, 0, 1, 0, 0, 1], [0, 1, 1, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 0, 1, 0],
                         [1, 0, 1, 0, 0, 1, 1, 0], [1, 0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 0, 1, 1],
                         [1, 1, 0, 1, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 1, 0, 1, 0],
                         [0, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 1, 0, 1],
                         [1, 0, 1, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0, 1, 1],
                         [0, 1, 1, 0, 1, 0, 0, 1], [1, 1, 0, 1, 0, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1, 0],
                         [0, 0, 1, 0, 1, 1, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1, 0],
                         [1, 0, 1, 1, 0, 1, 0, 0]];
    image = skeleton.copy();
    image = image / 255;
    intersections = list();
    for x in range(1, len(image) - 1):
        for y in range(1, len(image[x]) - 1):
            if image[x][y] == 1:
                neighbours = eight_neighbors(x, y, image);
                if neighbours in validIntersection:
                    intersections.append((y, x));

    for point1 in intersections:
        for point2 in intersections:
            if (((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) < 10 ** 2) and (point1 != point2):
                intersections.remove(point2);

    intersections = list(set(intersections));
    return intersections;

def measurement(directory_path):
    """Implements the core morphological feature extraction algorithm that computes 103 quantitative metrics from segmented mitochondrial images"""
    raise NotImplementedError("Function implementation has been masked")


def measurement_original_removed(directory_path):
    database = pd.DataFrame([[0] * 103],
                            columns=['cell_name', 'cell_mean_mito_area_(pixels_squared)', 'cell_median_mito_area_(pixels_squared)',
                                     'cell_std_mito_area_(pixels_squared)', 'cell_mean_mito_eccentricity',
                                     'cell_median_mito_eccentricity', 'cell_std_mito_eccentricity',
                                     'cell_mean_mito_equi_diameter_(pixels)', 'cell_median_mito_equi_diameter_(pixels)',
                                     'cell_std_mito_equi_diameter_(pixels)', 'cell_mean_mito_euler_number','cell_std_mito_euler_number',
                                     'cell_mean_mito_extent',
                                     'cell_median_mito_extent', 'cell_std_mito_extent',
                                     'cell_mean_mito_major_axis_(pixels)',
                                     'cell_median_mito_major_axis_(pixels)', 'cell_std_mito_major_axis_(pixels)',
                                     'cell_mean_mito_minor_axis_(pixels)',
                                     'cell_median_mito_minor_axis_(pixels)', 'cell_std_mito_minor_axis_(pixels)',
                                     'cell_mean_mito_orientation_(degrees)',
                                     'cell_median_mito_orientation_(degrees)', 'cell_std_mito_orientation_(degrees)',
                                     'cell_mean_mito_perimeter_(pixels)',
                                     'cell_median_mito_perimeter_(pixels)', 'cell_std_mito_perimeter_(pixels)',
                                     'cell_mean_mito_solidity',
                                     'cell_median_mito_solidity', 'cell_std_mito_solidity',
                                     'cell_mean_mito_centroid_x_(pixels)',
                                     'cell_median_mito_centroid_x_(pixels)', 'cell_std_mito_centroid_x_(pixels)',
                                     'cell_mean_mito_centroid_y_(pixels)',
                                     'cell_median_mito_centroid_y_(pixels)', 'cell_std_mito_centroid_y_(pixels)',
                                     'cell_mean_mito_distance_(pixels)',
                                     'cell_median_mito_distance_(pixels)', 'cell_std_mito_distance_(pixels)',
                                     'cell_mean_mito_weighted_cent_x_(pixels)',
                                     'cell_median_mito_weighted_cent_x_(pixels)',
                                     'cell_std_mito_weighted_cent_x_(pixels)',
                                     'cell_mean_mito_weighted_cent_y_(pixels)',
                                     'cell_median_mito_weighted_cent_y_(pixels)',
                                     'cell_std_mito_weighted_cent_y_(pixels)',
                                     'cell_mean_mito_weighted_distance_(pixels)',
                                     'cell_median_mito_weighted_distance_(pixels)',
                                     'cell_std_mito_weighted_distance_(pixels)',
                                     'cell_mean_mito_form_factor', 'cell_median_mito_form_factor',
                                     'cell_std_mito_form_factor', 'cell_mean_mito_roundness',
                                     'cell_median_mito_roundness',
                                     'cell_std_mito_roundness', 'cell_mean_mito_branch_count',
                                     'cell_std_mito_branch_count', 'cell_mean_mito_mean_branch_length_(pixels)',
                                     'cell_median_mito_mean_branch_length_(pixels)',
                                     'cell_std_mito_mean_branch_length_(pixels)',
                                     'cell_mean_mito_total_branch_length_(pixels)',
                                     'cell_median_mito_total_branch_length_(pixels)',
                                     'cell_std_mito_total_branch_length_(pixels)',
                                     'cell_mean_mito_median_branch_length_(pixels)',
                                     'cell_median_mito_median_branch_length_(pixels)',
                                     'cell_std_mito_median_branch_length_(pixels)',
                                     'cell_mean_mito_std_branch_length_(pixels)',
                                     'cell_std_mito_std_branch_length_(degrees)',
                                     'cell_mean_mito_mean_branch_angle_(degrees)',
                                     'cell_median_mito_mean_branch_angle_(degrees)',
                                     'cell_std_mito_mean_branch_angle_(degrees)',
                                     'cell_mean_mito_median_branch_angle_(degrees)',
                                     'cell_median_mito_median_branch_angle_(degrees)',
                                     'cell_std_mito_median_branch_angle_(degrees)',
                                     'cell_mean_mito_std_branch_angle_(degrees)',
                                     'cell_std_mito_std_branch_angle_(degrees)',
                                     'cell_mean_mito_total_density_(pixels)', 'cell_median_mito_total_density_(pixels)',
                                     'cell_std_mito_total_density', 'cell_mean_mito_average_density_(pixels)',
                                     'cell_median_mito_average_density_(pixels)',
                                     'cell_std_mito_average_density_(pixels)',
                                     'cell_mean_mito_median_density_(pixels)', 'cell_median_mito_median_density',
                                     'cell_std_mito_median_density_(pixels)', 'cell_kurtosis_x',
                                     'cell_weighted_kurtosis_x',
                                     'cell_kurtosis_y', 'cell_weighted_kurtosis_y', 'cell_kurtosis_squared',
                                     'cell_weighted_kurtosis_squared', 'cell_skewness_x', 'cell_weighted_skewness_x',
                                     'cell_skewness_y', 'cell_weighted_skewness_y', 'cell_skewness_squared',
                                     'cell_weighted_skewness_squared', 'cell_network_orientation_(degrees)',
                                     'cell_network_major_axis_(pixels)',
                                     'cell_network_minor_axis_(pixels)', 'cell_network_eccentricity',
                                     'cell_network_effective_extent', 'cell_network_effective_solidity',
                                     'cell_network_fractal_dimension'])

    database_raw = pd.DataFrame([[0] * 39], columns=['cell_name', 'resize_factor', 'mito_area', 'mito_centroid',
                                                     'mito_eccentricity',
                                                     'mito_equi_diameter', 'mito_euler_number', 'mito_extent',
                                                     'mito_major_axis',
                                                     'mito_minor_axis', 'mito_orientation', 'mito_perimeter',
                                                     'mito_solidity',
                                                     'mito_centroid_x', 'mito_centroid_y', 'mito_distance',
                                                     'mito_weighted_cent_x',
                                                     'mito_weighted_cent_y', 'mito_weighted_distance',
                                                     'mito_form_factor',
                                                     'mito_roundness', 'mito_branch_count', 'mito_total_branch_length',
                                                     'mito_mean_branch_length', 'mito_median_branch_length',
                                                     'mito_std_branch_length',
                                                     'mito_mean_branch_angle', 'mito_median_branch_angle',
                                                     'mito_std_branch_angle',
                                                     'mito_total_density', 'mito_average_density',
                                                     'mito_median_density',
                                                     'mito_branch_count', 'mito_distance', 'mito_weighted_cent_x',
                                                     'mito_weighted_cent_y',
                                                     'mito_weighted_distance', 'mito_form_factor', 'mito_roundness'])

    test_num = 0


Complete the function implementation replacing "raise NotImplementedError".