以下是一个案例代码

import SimpleITK as sitk
import numpy as np
import matplotlib.pyplot as plt
from radiomics import featureextractor
import os
import cv2


def load_image(image_path):
    image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)  # Load image in grayscale
    return sitk.GetImageFromArray(image)


if __name__ == '__main__':

    # 指定image和mask路径
    image_path = 'xxx_img.jpg'
    mask_path = 'xxx_mask.png'

    # 加载图像
    image = load_image(image_path)
    mask = load_image(mask_path)

    # 获取掩码
    mask = sitk.BinaryThreshold(mask, 1, 255, 1, 0)

    # 可视化
    plt.subplot(1, 2, 1)
    plt.imshow(sitk.GetArrayFromImage(image), cmap='gray')
    plt.title('Image')
    plt.subplot(1, 2, 2)
    plt.imshow(sitk.GetArrayFromImage(mask), cmap='gray')
    plt.title('Mask')
    plt.show()

    # 初始化特征提取器
    extractor = featureextractor.RadiomicsFeatureExtractor()

    # 提取特征
    features = extractor.execute(image, mask)

    # 打印特征
    for feature_name, feature_value in features.items():
        print(f'{feature_name}: {feature_value}')