Here is my experimental design:
-
Total of 1028 reference images, evenly divided into 4 categories: animals, people, nature, and food (256 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 400 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.
On a group level, all reference images should receive a similar number of ratings if possible.
My initial solution, involves generating separate condition files for each observer before running the experiment:
import csv
import random
Create a list of image categories and their corresponding range of image indices
categories = {
'animals': range(1, 257),
'people': range(257, 513),
'nature': range(513, 769),
'food': range(769, 1025)
}
Define the distortions and levels, adding an 'original' distortion type
distortions = ['01', '02', '03', 'orig']
levels = ['A', 'B', 'C']
Function to create a list of image tuples for a given category, distortion, and level
def image_combinations(category, distortion, level):
image_indices = categories[category]
if distortion == 'orig':
images = [(idx, distortion) for idx in image_indices]
else:
images = [(idx, f"{distortion}{level}") for idx in image_indices]
return images
all_image_combinations = []
Create a list of all possible image combinations
for category in categories:
for distortion in distortions:
distortion_level_combinations = [image_combinations(category, distortion, level) for level in levels]
for combination in distortion_level_combinations:
all_image_combinations.extend(combination)
Shuffle the list of all image combinations
random.shuffle(all_image_combinations)
num_observers = 300
images_per_observer = 416 # This will enable evenly distributing image combinations among observers
Assign image combinations to observers
observer_images = [[] for _ in range(num_observers)]
for i, combination in enumerate(all_image_combinations):
observer_index = i % num_observers
observer_images[observer_index].append(combination)
Write the observer images to separate CSV files
for observer_id, images in enumerate(observer_images, 1):
filename = f"conditions{observer_id}.csv"
with open(filename, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["image"])
for img, distortion in images:
filename = f"{img}{distortion}.jpg"
writer.writerow([filename])
However, this only returns 41 images per csv instead of 416 as requested. Please update it so it samples 416 or a similar amount for every single observer while obeying my overall requests