你好，请帮我在这个代码的基础上修改出一个，遍历每个uid文件夹下的6个视角的图片"rgb_%03d_%s.%s" % (set_idx, cond_view, suffix)，如果六个视角中有一个是视角的图片是只有黑色和白色两种颜色，就将这个uid加入到"only_black_and_white"json文件中。
import os
import numpy as np
from PIL import Image
import json


def compute_object_score(object_dir,
                         img_wh=(215, 215),
                         bg_color=(1, 1, 1),
                         alpha=None,
                         set_idx=0,
                         suffix='png'):
    # List of view types
    view_types = [
        'front', 'front_right', 'right', 'back', 'left', 'front_left'
    ]

    images = []
    for cond_view in view_types:
        # Construct the image path
        img_name = "rgb_%03d_%s.%s" % (set_idx, cond_view, suffix)

        img_path = os.path.join(object_dir, img_name)
        rgb_img = load_sketch(img_path,
                              img_wh,
                              bg_color,
                              alpha,
                              return_type='np')
        images.append(rgb_img)
        images.append(sketch_img)

    # Stack images into an array of shape (6, H, W, C)
    images_array = np.stack(images)  # shape: (6, H, W, C)
    # Compute the variance across the images at each pixel
    variance_per_pixel = np.var(images_array, axis=0)  # shape: (H, W, C)
    # Sum over all pixels to get total variance
    total_variance = np.sum(variance_per_pixel)
    # Alternatively, compute the average variance per pixel
    average_variance = total_variance / (
        images_array.shape[1] * images_array.shape[2] * images_array.shape[3])

    # Return the total variance as the score
    return total_variance






def load_image(self, img_path, bg_color, alpha, return_type='np'):
    # not using cv2 as may load in uint16 format
    # img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED) # [0, 255]
    # img = cv2.resize(img, self.img_wh, interpolation=cv2.INTER_CUBIC)
    # pil always returns uint8
    img = np.array(Image.open(img_path).resize(self.img_wh))
    img = img.astype(np.float32) / 255. # [0, 1]
    assert img.shape[-1] == 3 or img.shape[-1] == 4 # RGB or RGBA

    if alpha is None and img.shape[-1] == 4:
        alpha = img[:, :, 3:]
        img = img[:, :, :3]

    if alpha.shape[-1] != 1:
        alpha = alpha[:, :, None]

    img = img[...,:3] * alpha + bg_color * (1 - alpha)

    if return_type == "np":
        pass
    elif return_type == "pt":
        img = torch.from_numpy(img)
    else:
        raise NotImplementedError

    return img

uid_file = "/data/fl/dataset/objaverse/objaverse-list/half-part-objaverse-list/lvis-annotations-filtered-part-half.json" #44798
#annotations_file = "/data/fl/dataset/objaverse/lvis-annotations.json" #46207
paths_file = "/data/fl/dataset/objaverse/object-paths.json"
uid_data = json.load(open(uid_file))
paths_data = json.load(open(paths_file))

uid_scores = []  # 用于存储 (uid, score) 对的列表
for uid in uid_data:
    path = paths_data[uid]
    object_dir = os.path.join(
        "/data/fl/dataset/objaverse/lvis-subset/out_renderings/", path[5:-4])
    # 检查对象目录是否存在
    if not os.path.exists(object_dir):
        print(f"Object directory not found for uid: {uid}")
        continue
    try:
        # 计算分值
        score = compute_object_score(object_dir)
        sketch_score=compute_object_sketch_only_score(object_dir)
        # 将 (uid, score) 添加到列表
        uid_scores.append((uid, score,sketch_score))
        print("uid:", uid, "score:", score,"sketch score:",sketch_score)
    except Exception as e:
        print(f"Error processing uid {uid}: {e}")
        continue  # 跳过出错的uid，继续处理下一个

# 对列表按照分值从高到低排序
uid_scores_sum_sorted = sorted(uid_scores, key=lambda x: x[1], reverse=True)
uid_scores_sketch_sorted = sorted(uid_scores, key=lambda x: x[2], reverse=True)
# 取前50个
top_50_sum = uid_scores_sum_sorted[:50]
top_50_sketch = uid_scores_sketch_sorted[:50]
# 提取uids
top_50_sum_uids = [uid for uid, score, sketch_score in top_50_sum]
for uid, score, sketch_score in top_50_sum:
    print(f"UID: {uid}, Score: {score}, Sketch Score: {sketch_score}")
print("---------------------------")
top_50_sketch_uids = [uid for uid, score, sketch_score in top_50_sketch]
for uid, score, sketch_score in top_50_sketch:
    print(f"UID: {uid}, Score: {score}, Sketch Score: {sketch_score}")

# 将top50 sum rgb score and sketch score的uid保存到json文件
with open('top_50_sum_core_validation_lvis.json', 'w') as f:
    json.dump(top_50_sum_uids, f)

print("Top 50 uids have been saved to 'top_50_core_validation_lvis.json'")

# 将top50  sketch score的uid保存到json文件
with open('top_50_sketch_core_validation_lvis.json', 'w') as f:
    json.dump(top_50_sketch_uids, f)

print("Top 50 uids have been saved to 'top_50_sketch_core_validation_lvis.json'")
w') as f:
    json.dump(top_50_sketch_uids, f)

print("Top 50 uids have been saved to 'top_50_sketch_core_validation_lvis.json'")