I have 540 reference images consisting of 3 categories (180 images each). The images can…
- User
I have 540 reference images consisting of 3 categories (180 images each). The images can have 3 distortions (1,2,3) each at 3 levels (a,b,c) or they can be original. I want each observer to see the same number of images from each category. Moreover, I want all image conditions (distortions and orginals) to be equally present on each category. To ensure this, I need to have a total number of trials that is divisible by 30 (3 image categories and 10 image configurations)
Here is an example for 360 trials (12*30):
Set seed so they can be prepoduced
From each category, sample 120 images
shuffle and add to list of all permutations (original & A-C * 1-3)
Combine categories and shuffle.
Generate a few hundred of these lists and save them as indivual csv files each of which will be used to select images for one observer to rate.
My question is what can be done to keep similar amount of images overall between observers while obeying the above structure that is established above? This procedure could make a certain image ref1_dist1_levA being shown more times than ref1_dist1_levB when when the experiment is completed. Is there any way to balance this (at least partially)? It is a must that each observer follow the given logic. Please give a solution in python code.
- Assistant
In order to balance the number of times each image is shown across different observers, you can create a set of permutations and then rotate through the permutations for each new observer.
- User
This code returns a series of csvs each with a a single row containing "Image"
- Assistant
Apologies for the confusion. I made a mistake in writing the rows to the CSV. I will correct the code for writing the CSV files below:
python# Generating observer assignments and saving as CSV files num_observers = 100 observer_assignments = generate_observer_assignments(num_observers) for i, observer_images in enumerate(observer_assignments): with open(f'observer_{i + 1}_assignment.csv', 'w', newline='') as csvfile: writer = csv.writer(csvfile) writer.writerow(['Image']) for image in observer_images: writer.writerow([image])With this corrected code, you should see CSV files with correct image assignments, each having separate rows for each image.
- User
Here is the code you gave me. It returns a series of csv files that all only contain "Image".
import random import itertools import csv
random.seed(42) # Set seed for reproducibility
num_trials = 360 num_image_configs = 10 num_image_per_cat = 180 num_categories = 3
Creating the image conditions within each category
distortions = [f'{d}{l}' for d in [1, 2, 3] for l in ['a', 'b', 'c']] + ['original']
Creating the image list within each category
image_lists = [[f'{category}_{distortion}' for distortion in distortions] for category in range(num_categories)]
Generating all possible assignments within each category
assignment_permutations = [list(itertools.permutations(image_list, num_trials // (num_categories * num_image_configs))) for image_list in image_lists]
Function to rotate through the permutations
- Assistant
Apologies for the continuous issue. I misunderstood the problem in the provided script. The issue is with the way we're creating
assignment_permutations. We're unintentionally generating all the permutations, which is computationally expensive and unnecessary. Instead, we should just shuffle the image list within each category and create image configurations according to the number of trials. Here's the corrected script:python