Here is my experimental design: - Total of 840 reference images, evenly divided into 3…
- User
Here is my experimental design:
-
Total of 840 reference images, evenly divided into 3 categories: animals, people, nature, and (280 images per category).
-
Each image can have 3 distortions applied to them (01, 02, 03), and each distortion has 3 levels (A, B, C).
-
I want approximately 300 observers to rate around 420 reference images each such that on the observer level:
- Each observer rates an equal number of images from each of the 4 categories.
- The distortions and levels are evenly applied within each category.
- Each reference image is maximally seen once by each observer.
A less important priority is that on a group level, all reference images should receive a similar number of ratings if possible and not compromise with the above goals.
Please propose python code to generate a csv with images for each observer. The image format could be as follows 637_03_A_nature.jpg
-
- Assistant
Based on your experimental design, you can use the following Python script with some modifications to achieve your requirements. The provided code generates the CSV file where each row represents an observer, and each observer will have their assigned image IDs as columns.
import pandas as pd import random import csv total_images = 840 images_per_category = 280 categories = ["animals", "people", "nature"] distortions = ["01", "02", "03"] levels = ["A", "B", "C"] observers = 300 # generate list of image_ids image_ids = list(range(1, total_images + 1)) # divide the image_ids into categories category_dict = {} for i, cat in enumerate(categories): ids = image_ids[i * images_per_category:(i + 1) * images_per_category] category_dict[cat] = ids # assign distortions and levels to each image within each category cat_dis_lev_img_ids = [] for cat in categories: for dis in distortions: for lev in levels: for img_id in category_dict[cat]: cat_dis_lev_img_id = f"{img_id}_{dis}_{lev}_{cat}.jpg" cat_dis_lev_img_ids.append(cat_dis_lev_img_id) observers_assignments = [] # assign images to each observer while maintaining conditions for _ in range(observers): observer_images = [] for cat in categories: cat_images = [img for img in cat_dis_lev_img_ids if f"_{cat}.jpg" in img] cat_images_per_observer = len(cat_images) // observers selected_images = random.sample(cat_images, cat_images_per_observer) observer_images.extend(selected_images) cat_dis_lev_img_ids = [img for img in cat_dis_lev_img_ids if img not in selected_images] observers_assignments.append(observer_images) # write the observer assignments to a CSV file with open("observer_image_assignments.csv", "w", newline="") as csvfile: writer = csv.writer(csvfile) for observer_images in observers_assignments: writer.writerow(observer_images)