Add generation scripts for all tasks

#3
README.md CHANGED
@@ -20,7 +20,7 @@ size_categories:
20
 
21
  Percept-V is a benchmark of **30 synthetic visual perception tasks**, 200 samples each (**6,000 samples total**), designed to isolate *perception* from *reasoning* in vision-language models. Every task is procedurally generated from simple primitives — circles, lines, grids, shapes, colours — so a model that genuinely sees the image should solve it near-perfectly, and failures point at perceptual rather than reasoning limits.
22
 
23
- Tasks span counting, colour identification, shape identification, spatial localisation, layering/occlusion, grid navigation, and two-image comparison. Each task ships with its images, ground truth, prompts, and the exact parsing and scoring scripts used to evaluate it.
24
 
25
  ## Repository layout
26
 
@@ -35,10 +35,13 @@ Each task is a self-contained directory:
35
  │ ├── input_prompt.txt # describes what the image contains
36
  │ ├── rules.txt # the task the model must perform
37
  │ └── output_prompt.txt # required output format
 
38
  ├── utils.py # parses raw model text into a structured answer
39
  └── eval.py # scores parsed answers against the ground truth
40
  ```
41
 
 
 
42
  ### Prompt construction
43
 
44
  The three prompt files are fragments meant to be concatenated into a single instruction, e.g. for `sort_lines`:
@@ -197,8 +200,29 @@ Eight tasks — `circle_right_triangle`, `cross_and_knots`, `graph_counting`, `g
197
  - `eval.py` takes `--answer`/`-a` and `--output`/`-o`; the defaults refer to files that are not shipped here, so pass both explicitly.
198
  - Several `utils.py` files contain a second, commented-out `output_from_text` inside a triple-quoted string, left over from earlier prompt formats. Only the live top-level definition is used.
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  ## Changelog
201
 
 
 
202
  - **2026-09-11 — `colours_present` ground truth corrected.** In earlier versions of `colours_present/data.json`, the 20 yes/no answers were listed in a different colour order from the one given in `rules.txt`, so 183 of the 200 records had wrong labels. Scores on this task computed before this date are not valid. `colours_present/eval.py` now takes the gold labels from `data.json` (matched on `id`) instead of from the answer file, so re-running it on existing answer files gives corrected scores without repeating inference. It prints a note when an answer file still carries the old labels, and accepts `--gold` to point at a different `data.json`. The task is single-image; the table and loader above are updated accordingly.
203
 
204
  ## Licence
 
20
 
21
  Percept-V is a benchmark of **30 synthetic visual perception tasks**, 200 samples each (**6,000 samples total**), designed to isolate *perception* from *reasoning* in vision-language models. Every task is procedurally generated from simple primitives — circles, lines, grids, shapes, colours — so a model that genuinely sees the image should solve it near-perfectly, and failures point at perceptual rather than reasoning limits.
22
 
23
+ Tasks span counting, colour identification, shape identification, spatial localisation, layering/occlusion, grid navigation, and two-image comparison. Each task ships with its images, ground truth, prompts, the script that generated them, and the exact parsing and scoring scripts used to evaluate it.
24
 
25
  ## Repository layout
26
 
 
35
  │ ├── input_prompt.txt # describes what the image contains
36
  │ ├── rules.txt # the task the model must perform
37
  │ └── output_prompt.txt # required output format
38
+ ├── script.py # generator that produced data/ and data.json
39
  ├── utils.py # parses raw model text into a structured answer
40
  └── eval.py # scores parsed answers against the ground truth
41
  ```
42
 
43
+ `colours_present`, `layered_colours` and `list_colours` also contain `swatches.png`, the colour reference strip their generator appends below each image.
44
+
45
  ### Prompt construction
46
 
47
  The three prompt files are fragments meant to be concatenated into a single instruction, e.g. for `sort_lines`:
 
200
  - `eval.py` takes `--answer`/`-a` and `--output`/`-o`; the defaults refer to files that are not shipped here, so pass both explicitly.
201
  - Several `utils.py` files contain a second, commented-out `output_from_text` inside a triple-quoted string, left over from earlier prompt formats. Only the live top-level definition is used.
202
 
203
+ ## Regenerating the data
204
+
205
+ `<task>/script.py` is the generator used for the released data. The one exception is `colours_present/script.py`, which includes the 2026-09-11 fix, so its output now matches the corrected labels. Each task was produced by a single call with 10 images per difficulty level:
206
+
207
+ ```bash
208
+ mkdir -p gen/counting_circles && cd gen/counting_circles # use an empty directory
209
+ cp <path-to-Percept-V>/counting_circles/script.py .
210
+ python script.py --num_images 10 --num_sizes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
211
+ ```
212
+
213
+ - **Difficulty levels:** `--num_sizes` is 1–20 for every task except `grid_path` and `maze_solving`, which use 3–22. `circle_right_triangle`, `cross_and_knots`, `grid_path`, `locate_circles_colour` and `locate_circles_shape` use their default `--grid_size 6`.
214
+ - **Output location:** the script writes `data/` and `data.json` into the **current directory**, overwriting existing ones, so do not run it inside a downloaded copy of this dataset. File numbering starts at `--file` (default 1).
215
+ - **No fixed random seeds:** a run produces a new sample from the same distribution, not the released images.
216
+ - **Requirements:** Python 3 with `numpy`, `matplotlib` and `Pillow`, plus `opencv-python` (imported by `colours_present`, `layered_colours`, `list_colours`, `mirror_image`, `water_image`) and `networkx` (`graph_counting`).
217
+ - **Files the scripts read from the working directory:**
218
+ - `swatches.png`, for `colours_present`, `layered_colours` and `list_colours`: copy it from the task directory.
219
+ - An Arial font file, named `arial.ttf` (`grid_path`, `locate_circles_colour`, `locate_circles_shape`) or `ARIAL.ttf` (`sort_lines`). It is not included in this repository. If Pillow finds it neither in the working directory nor in the system font folders, `grid_path` and `sort_lines` stop with an error, and the two `locate_circles` tasks fall back to Pillow's much smaller default font.
220
+ - Background images `background_image/bg_1.png` … `bg_10.png`, for `list_colours` and `list_shapes`. These are not included in this repository.
221
+
222
  ## Changelog
223
 
224
+ - **2026-09-11 — Generation scripts added.** Every task directory now includes its `script.py`, plus `swatches.png` where the generator needs it. See "Regenerating the data".
225
+
226
  - **2026-09-11 — `colours_present` ground truth corrected.** In earlier versions of `colours_present/data.json`, the 20 yes/no answers were listed in a different colour order from the one given in `rules.txt`, so 183 of the 200 records had wrong labels. Scores on this task computed before this date are not valid. `colours_present/eval.py` now takes the gold labels from `data.json` (matched on `id`) instead of from the answer file, so re-running it on existing answer files gives corrected scores without repeating inference. It prints a note when an answer file still carries the old labels, and accepts `--gold` to point at a different `data.json`. The task is single-image; the table and loader above are updated accordingly.
227
 
228
  ## Licence
change_colour/script.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+ import sys
3
+ import random
4
+ import os
5
+ import json
6
+ import argparse
7
+ import random
8
+
9
+
10
+ def create_images(num_images, num_objects_list , file):
11
+ # Ensure that the directory exists
12
+ # output_dir = "./data"
13
+ output_dir = os.path.join(os.getcwd(), "data")
14
+ if not os.path.exists(output_dir):
15
+ os.makedirs(output_dir)
16
+
17
+ data = []
18
+ image_width, image_height = 1500, 1000
19
+ append = (file != 1)
20
+ for num_objects in num_objects_list:
21
+ max_obj = num_objects*2
22
+ for img_index in range(num_images):
23
+ # Create a blank white image
24
+ image = Image.new("RGB", (image_width, image_height), "white")
25
+ draw = ImageDraw.Draw(image)
26
+
27
+ # List to hold positions of circles
28
+ colour_dict = {1: "red", 2: "blue", 3: "green"}
29
+ colours1 = []
30
+ colours2 = []
31
+ positions = []
32
+
33
+ # Randomly select a radius for each circle
34
+ radii = [random.randint(10, 30) for _ in range(max_obj)]
35
+
36
+ # Generate non-overlapping positions for the circles
37
+ while len(positions) < max_obj:
38
+ x = random.randint(max(radius for radius in radii), image_width - max(radius for radius in radii))
39
+ y = random.randint(max(radius for radius in radii), image_height - max(radius for radius in radii))
40
+
41
+ # Check if the new circle overlaps or touches any existing circles
42
+ overlap = False
43
+ for (px, py, r) in positions:
44
+ distance = ((px - x) ** 2 + (py - y) ** 2) ** 0.5
45
+ if distance < r + max(radii):
46
+ overlap = True
47
+ break
48
+
49
+ if not overlap:
50
+ radius = radii[len(positions)]
51
+ positions.append((x, y, radius))
52
+ colours1.append(colour_dict[random.randint(1, 3)])
53
+ """colours2.append(colour_dict[random.randint(1, 3)])
54
+ if(colours1[-1] != colours2[-1]):
55
+ difference += 1"""
56
+
57
+ colours2 = colours1.copy()
58
+ indices = random.sample(range(0, max_obj), num_objects)
59
+ for index in indices:
60
+ if(colours2[index] == 'red'):
61
+ colours2[index] = 'blue'
62
+ elif(colours2[index] == 'blue'):
63
+ colours2[index] = 'green'
64
+ else:
65
+ colours2[index] = 'red'
66
+
67
+ # Draw the circles
68
+ i=0
69
+ for (x, y, radius) in positions:
70
+ draw.ellipse([x - radius, y - radius, x + radius, y + radius], fill=colours1[i])
71
+ i=i+1
72
+
73
+ # Save the image with the filename `firsti.png`
74
+ image_filename = f"first{file}.png"
75
+ image_path = os.path.join(output_dir, image_filename)
76
+ image.save(image_path)
77
+
78
+ i=0
79
+ for (x, y, radius) in positions:
80
+ draw.ellipse([x - radius, y - radius, x + radius, y + radius], fill=colours2[i])
81
+ i=i+1
82
+
83
+ #Save the image with the filename `secondi.png`
84
+ image_filename = f"second{file}.png"
85
+ file += 1
86
+ image_path = os.path.join(output_dir, image_filename)
87
+ image.save(image_path)
88
+
89
+
90
+
91
+ # Store the number of objects in the data dictionary
92
+ # data[image_filename] = {
93
+ # "num_objects": num_objects
94
+ # }
95
+ gold_output = {
96
+ "id": image_filename,
97
+ "num_differences": num_objects
98
+ }
99
+ data.append(gold_output)
100
+
101
+ # print(f"Image saved at: {image_path}")
102
+
103
+ if append:
104
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
105
+ old_data = json.load(f)
106
+ old_data.extend(data)
107
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
108
+ json.dump(old_data, f, indent=2)
109
+ else:
110
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
111
+ json.dump(data, f, indent=2)
112
+
113
+ if __name__ == "__main__":
114
+ # Parse command line arguments
115
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
116
+ parser.add_argument(
117
+ '--num_images',
118
+ type=int,
119
+ help='Number of images to generate',
120
+ default=1
121
+ )
122
+ parser.add_argument(
123
+ '--num_sizes',
124
+ nargs='*',
125
+ type=int,
126
+ help='List of count of circles',
127
+ default=[5]
128
+ )
129
+ parser.add_argument(
130
+ '--file',
131
+ type=int,
132
+ help='Starting file number',
133
+ default=1
134
+ )
135
+ args = parser.parse_args()
136
+ file = args.file
137
+ num_object_list = args.num_sizes
138
+ append = (file != 1)
139
+ create_images(args.num_images, num_object_list , file)
circle_boxes/script.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import PIL
3
+ from PIL import Image
4
+ import random
5
+ import numpy as np
6
+ import os
7
+ import json
8
+ import argparse
9
+
10
+ def generate_shapes(num_images, num_objects_list , file):
11
+ # Set up the plot
12
+
13
+ output_dir = os.path.join(os.getcwd(), "data")
14
+ input_dir = os.path.join(os.getcwd(), "background_image")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ append = (file != 1)
20
+
21
+ for n in num_objects_list:
22
+ max_objects = 2*n
23
+ for img_index in range(num_images):
24
+ width, height = 1500, 1000
25
+ fig, ax = plt.subplots()
26
+ ax.set_aspect('equal')
27
+ plt.axis('off')
28
+ #fig.set_figheight(height)
29
+ #fig.set_figwidth(width)
30
+ ax.set_xlim(-1500, 1500)
31
+ ax.set_ylim(-1000, 1000)
32
+
33
+ plt.axvline(x = 0, color = 'blue')
34
+ # Generate random positions for the shapes
35
+ left = random.randint(0, max_objects)
36
+ right = max_objects-left
37
+ positions_left, positions_right = [], []
38
+ radius = 30
39
+
40
+ """shape = plt.Rectangle((-(width - radius), 50), 2850, 875, ec="blue", fill=False)
41
+ ax.add_patch(shape)
42
+ shape = plt.Rectangle((-(width - radius), -50), 2850, 875, ec="blue", fill=False)
43
+ ax.add_patch(shape)"""
44
+
45
+ for i in range(left):
46
+ while True:
47
+ x, y = random.randint(-(width-radius), -radius), random.randint(-(height-radius), (height-radius))
48
+ # Ensure shapes don't overlap
49
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions_left) and (abs(x) > radius and abs(y) > radius):
50
+ positions_left.append((x, y))
51
+ break
52
+
53
+ for i in range(right):
54
+ while True:
55
+ x, y = random.randint(radius, (width-radius)), random.randint(-(height-radius), (height-radius))
56
+ # Ensure shapes don't overlap
57
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions_right) and (abs(x) > radius and abs(y) > radius):
58
+ positions_right.append((x, y))
59
+ break
60
+
61
+ # Draw shapes and label them
62
+ """first, second, third, fourth = 0, 0, 0, 0
63
+ plt.axhline(0, color='black', linewidth=0.5)
64
+ plt.axvline(0, color='black', linewidth=0.5)"""
65
+
66
+ for i, (x, y) in enumerate(positions_left):
67
+ shape = plt.Circle((x, y), radius, color='red')
68
+ ax.add_patch(shape)
69
+ #ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
70
+
71
+ for i, (x, y) in enumerate(positions_right):
72
+ shape = plt.Circle((x, y), radius, color='red')
73
+ ax.add_patch(shape)
74
+
75
+ # Save the plot to a file
76
+ filename = f"{file}.png"
77
+ file += 1
78
+ filepath = os.path.join(output_dir, filename)
79
+ plt.savefig(filepath, bbox_inches='tight')
80
+ plt.close()
81
+
82
+ answer = max(left, right) - n
83
+
84
+ gold_output = {
85
+ "id": filename,
86
+ "answer": answer,
87
+ "num_objects": n
88
+ }
89
+ data.append(gold_output)
90
+
91
+
92
+ if append:
93
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
94
+ old_data = json.load(f)
95
+ old_data.extend(data)
96
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
97
+ json.dump(old_data, f, indent=2)
98
+ else:
99
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
100
+ json.dump(data, f, indent=2)
101
+
102
+
103
+
104
+ # # Example usage
105
+ # generate_shapes(10, 'shapes.png')
106
+ if __name__ == "__main__":
107
+ # Parse command line arguments
108
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
109
+ parser.add_argument(
110
+ '--num_images',
111
+ type=int,
112
+ help='Number of images to generate',
113
+ default=1
114
+ )
115
+ parser.add_argument(
116
+ '--num_sizes',
117
+ nargs='*',
118
+ type=int,
119
+ help='List of count of objects',
120
+ default=[5]
121
+ )
122
+ parser.add_argument(
123
+ '--file',
124
+ type=int,
125
+ help='Starting file number',
126
+ default=1
127
+ )
128
+ args = parser.parse_args()
129
+ file = args.file
130
+ num_object_list = args.num_sizes
131
+ append = (file != 1)
132
+ generate_shapes(args.num_images, num_object_list , file)
circle_location/script.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import PIL
3
+ from PIL import Image
4
+ import random
5
+ import numpy as np
6
+ import os
7
+ import json
8
+ import argparse
9
+
10
+ def generate_shapes(num_images, num_objects_list , file):
11
+ # Set up the plot
12
+
13
+ output_dir = os.path.join(os.getcwd(), "data")
14
+ input_dir = os.path.join(os.getcwd(), "background_image")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ append = (file != 1)
20
+
21
+ for n in num_objects_list:
22
+ for img_index in range(num_images):
23
+ #im = Image.open(os.path.join(input_dir, f"bg_{img_index+1}.png"))
24
+ fig, ax = plt.subplots()
25
+ #ax.imshow(im)
26
+ ax.set_aspect('equal')
27
+ plt.axis('off')
28
+
29
+ # Adjust plot limits to prevent cutoff
30
+ plt.xlim(-1500.0, 1500.0)
31
+ plt.ylim(-1000, 1000)
32
+
33
+ # Generate random positions for the shapes
34
+ positions = []
35
+ radius = 75
36
+ height, width = 1000, 1500
37
+
38
+ for i in range(n):
39
+ while True:
40
+ x, y = random.randint(-(width - radius), (width - radius)), random.randint(-(height - radius), (height-radius))
41
+ # Ensure shapes don't overlap
42
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions) and (abs(x) > radius and abs(y) > radius):
43
+ positions.append((x, y))
44
+ break
45
+
46
+ # Draw shapes and label them
47
+ first, second, third, fourth = 0, 0, 0, 0
48
+ plt.axhline(0, color='black', linewidth=0.5)
49
+ plt.axvline(0, color='black', linewidth=0.5)
50
+
51
+ for i, (x, y) in enumerate(positions):
52
+ #color = random.choice(colours)
53
+ #shape_type = random.choice(shapes)
54
+ if x>0 and y>0:
55
+ first += 1
56
+ elif x<0 and y>0:
57
+ second += 1
58
+ elif x<0 and y<0:
59
+ third += 1
60
+ else:
61
+ fourth += 1
62
+
63
+ shape = plt.Circle((x, y), radius, color='black')
64
+ ax.add_patch(shape)
65
+ #ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
66
+
67
+ # Save the plot to a file
68
+ filename = f"{file}.png"
69
+ file += 1
70
+ filepath = os.path.join(output_dir, filename)
71
+ plt.savefig(filepath, bbox_inches='tight')
72
+ plt.close()
73
+ iterable = [first, second, third, fourth]
74
+ answer = max(enumerate(iterable), key=lambda x: x[1])[0] + 1
75
+
76
+ gold_output = {
77
+ "id": filename,
78
+ "quadrant": answer,
79
+ "count": iterable[answer-1],
80
+ "num_objects": n
81
+ }
82
+ data.append(gold_output)
83
+
84
+
85
+ if append:
86
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
87
+ old_data = json.load(f)
88
+ old_data.extend(data)
89
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
90
+ json.dump(old_data, f, indent=2)
91
+ else:
92
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
93
+ json.dump(data, f, indent=2)
94
+
95
+
96
+
97
+ # # Example usage
98
+ # generate_shapes(10, 'shapes.png')
99
+ if __name__ == "__main__":
100
+ # Parse command line arguments
101
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
102
+ parser.add_argument(
103
+ '--num_images',
104
+ type=int,
105
+ help='Number of images to generate',
106
+ default=1
107
+ )
108
+ parser.add_argument(
109
+ '--num_sizes',
110
+ nargs='*',
111
+ type=int,
112
+ help='List of count of objects',
113
+ default=[5]
114
+ )
115
+ parser.add_argument(
116
+ '--file',
117
+ type=int,
118
+ help='Starting file number',
119
+ default=1
120
+ )
121
+ args = parser.parse_args()
122
+ file = args.file
123
+ num_object_list = args.num_sizes
124
+ append = (file != 1)
125
+ generate_shapes(args.num_images, num_object_list , file)
circle_right_triangle/script.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+ import random
4
+ import argparse
5
+ import os
6
+ import json
7
+
8
+ def create_shape_grid(rows, cols, circles_count, triangles_count):
9
+ # Initialize the grid
10
+ #right = random.choice([True, False])
11
+ grid = np.empty((rows, cols), dtype=object)
12
+
13
+ # Fill the grid with None
14
+ for i in range(rows):
15
+ for j in range(cols):
16
+ grid[i, j] = None
17
+
18
+
19
+ triangle_positions = []
20
+
21
+ # Place triangles in the grid
22
+ for _ in range(triangles_count):
23
+ while True:
24
+ row, col = random.randint(0, rows - 1), random.randint(0, cols - 1)
25
+ if grid[row, col] is None:
26
+ grid[row, col] = 'triangle'
27
+ triangle_positions.append((row, col))
28
+ # shapes_placed += 1
29
+ break
30
+
31
+ """shapes_placed = 0
32
+ if right:
33
+ #place atleast one circle to right of triangle and rest randomly
34
+ placed_right = False
35
+ for row, col in triangle_positions:
36
+ if col < cols - 1 and grid[row, col + 1] is None:
37
+ placed_right = True
38
+ grid[row, col + 1] = 'circle'
39
+ shapes_placed += 1
40
+ break
41
+
42
+ if not placed_right:
43
+ right = False
44
+
45
+ while shapes_placed < circles_count:
46
+ row, col = random.randint(0, rows - 1), random.randint(0, cols - 1)
47
+ if grid[row, col] is None:
48
+ grid[row, col] = 'circle'
49
+ shapes_placed += 1
50
+
51
+ else:
52
+ #no circle should be placed to the right of triangle
53
+ while shapes_placed < circles_count:
54
+ row, col = random.randint(0, rows - 1), random.randint(0, cols - 1)
55
+ if col == 0 or grid[row, col - 1] != 'triangle':
56
+ if grid[row, col] is None:
57
+ grid[row, col] = 'circle'
58
+ shapes_placed += 1"""
59
+
60
+ positions = []
61
+ for i in range(rows):
62
+ for j in range(cols):
63
+ positions.append((i, j))
64
+
65
+ for pos in triangle_positions:
66
+ positions.remove(pos)
67
+
68
+ circle_positions = random.sample(positions, circles_count)
69
+ for i, tup in enumerate(circle_positions):
70
+ row, col = tup[0], tup[1]
71
+ grid[row, col] = 'circle'
72
+
73
+ right = False
74
+ for i in range(rows):
75
+ for j in range(cols-1):
76
+ if grid[i, j] == 'triangle' and grid[i, j+1] == 'circle':
77
+ right = True
78
+ break
79
+
80
+ return grid , right
81
+
82
+ def draw_grid(grid):
83
+ global file, output_dir
84
+ fig, ax = plt.subplots(figsize=(8, 8))
85
+ ax.set_xlim(0, grid.shape[1])
86
+ ax.set_ylim(0, grid.shape[0])
87
+ ax.set_xticks(np.arange(0, grid.shape[1] + 1))
88
+ ax.set_yticks(np.arange(0, grid.shape[0] + 1))
89
+ ax.grid(True)
90
+
91
+ # Create cell outlines
92
+ for i in range(grid.shape[0] + 1):
93
+ ax.axhline(i, color='black', lw=1)
94
+ for j in range(grid.shape[1] + 1):
95
+ ax.axvline(j, color='black', lw=1)
96
+
97
+ for (i, j), shape in np.ndenumerate(grid):
98
+ if shape == 'circle':
99
+ circle = plt.Circle((j + 0.5, grid.shape[0] - (i + 0.5)), 0.4, color='blue', ec='black')
100
+ ax.add_artist(circle)
101
+ elif shape == 'triangle':
102
+ triangle = plt.Polygon([[j + 0.5, grid.shape[0] - (i + 0.1)],
103
+ [j + 0.1, grid.shape[0] - (i + 0.8)],
104
+ [j + 0.9, grid.shape[0] - (i + 0.8)]],
105
+ color='red', ec='black')
106
+ ax.add_artist(triangle)
107
+
108
+ ax.set_aspect('equal')
109
+ plt.title('Grid of Circles and Triangles')
110
+
111
+ #1 Save the image if the output directory exists
112
+ image_filename = f"{file}.png"
113
+ file += 1
114
+ image_path = os.path.join(output_dir, image_filename)
115
+
116
+ # Uncomment below if you want to save the figure
117
+ plt.savefig(image_path)
118
+ plt.close()
119
+
120
+ # plt.show()
121
+
122
+ # # Input for grid dimensions, number of circles, and triangles
123
+ # num_rows = 5 # Number of rows
124
+ # num_cols = 5 # Number of columns
125
+ # num_circles = 3 # Number of circles
126
+ # num_triangles = 3 # Number of triangles
127
+
128
+ # grid = create_shape_grid(num_rows, num_cols, num_circles, num_triangles)
129
+ # draw_grid(grid)
130
+
131
+ if __name__ == "__main__":
132
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
133
+ parser.add_argument(
134
+ '--num_images',
135
+ type=int,
136
+ help='Number of images to generate',
137
+ default=1
138
+ )
139
+ parser.add_argument(
140
+ '--num_sizes',
141
+ nargs='*',
142
+ help='List of n values (grid size , number of shapes) to generate',
143
+ default=[3 , 1]
144
+ )
145
+ parser.add_argument(
146
+ '--grid_size',
147
+ type=int,
148
+ help='Grid size',
149
+ default=6
150
+ )
151
+ parser.add_argument(
152
+ '--file',
153
+ type=int,
154
+ help='Starting file number',
155
+ default=1
156
+ )
157
+ args = parser.parse_args()
158
+ file = args.file
159
+ num_sizes = args.num_sizes
160
+ data = []
161
+ append = (file != 1)
162
+ output_dir = os.path.join(os.getcwd(), "data")
163
+ if not os.path.exists(output_dir):
164
+ os.makedirs(output_dir)
165
+
166
+ for j in range(0, len(num_sizes)):
167
+ for i in range(args.num_images):
168
+ rows, cols = args.grid_size, args.grid_size
169
+ circles = int(num_sizes[j])
170
+ triangles = min(int(num_sizes[j]), args.grid_size**2 - int(num_sizes[j]))
171
+ grid,right = create_shape_grid(rows, cols, circles, triangles)
172
+ # print(grid)
173
+ data.append({
174
+ 'id': f"{file}.png",
175
+ 'rows': rows,
176
+ 'cols': cols,
177
+ 'circles': circles,
178
+ 'triangles': triangles,
179
+ 'right': right
180
+ })
181
+ draw_grid(grid)
182
+ if append:
183
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
184
+ old_data = json.load(f)
185
+ old_data.extend(data)
186
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
187
+ json.dump(old_data, f, indent=2)
188
+ else:
189
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
190
+ json.dump(data, f, indent=2)
colours_present/script.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import cv2
3
+ import PIL
4
+ from PIL import Image
5
+ import random
6
+ import numpy as np
7
+ import os
8
+ import json
9
+ import argparse
10
+
11
+ def generate_shapes(num_images, num_objects_list , file):
12
+ # Set up the plot
13
+
14
+ output_dir = os.path.join(os.getcwd(), "data")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ append = (file != 1)
20
+
21
+ for n in num_objects_list:
22
+ for img_index in range(num_images):
23
+ fig, ax = plt.subplots()
24
+ ax.set_aspect('equal')
25
+ plt.axis('off')
26
+
27
+ # Adjust plot limits to prevent cutoff
28
+ plt.xlim(-0.1, 1.1)
29
+ plt.ylim(-0.1, 1.1)
30
+
31
+ # Generate random positions for the shapes
32
+ positions = []
33
+ radius = 0.05
34
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
35
+ # Must be a list in the order given in prompts/rules.txt: gold_answer is built by
36
+ # iterating it. (A set here made the gold order depend on the process's hash seed.)
37
+ colours = ['black', 'gray', 'brown', 'maroon', 'red', 'coral', 'tan', 'orange', 'ivory', 'goldenrod', 'yellow', 'green', 'olive', 'turquoise', 'skyblue', 'blue', 'lavender', 'purple', 'pink', 'fuchsia']
38
+ colours_n = random.sample(colours, n)
39
+
40
+ gold_answer = []
41
+ for i in colours:
42
+ if i in colours_n:
43
+ gold_answer.append('Yes')
44
+ else:
45
+ gold_answer.append('No')
46
+
47
+ for i in range(n):
48
+ while True:
49
+ x, y = random.uniform(0.1, 0.9), random.uniform(0.1, 0.9)
50
+ # Ensure shapes don't overlap
51
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
52
+ positions.append((x, y))
53
+ break
54
+
55
+ # Choose one odd-colored shape
56
+ #odd_index = random.randint(0, n - 1)
57
+
58
+ # Draw shapes and label them
59
+ for i, (x, y) in enumerate(positions):
60
+ color = colours_n[i]
61
+ shape_type = random.choice(shapes)
62
+
63
+ if shape_type == 'circle':
64
+ shape = plt.Circle((x, y), radius, ec='black', color=color)
65
+ elif shape_type == 'triangle':
66
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
67
+ shape = plt.Polygon(triangle, ec='black', color=color)
68
+ elif shape_type == 'rectangle':
69
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, ec='black', color=color)
70
+ elif shape_type == 'pentagon':
71
+ pentagon = np.array([
72
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
73
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
74
+ [x - 0.95 * radius, y + 0.31 * radius]
75
+ ])
76
+ shape = plt.Polygon(pentagon, ec='black', color=color)
77
+
78
+ ax.add_patch(shape)
79
+ #ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
80
+
81
+ # Save the plot to a file
82
+ filename = f"{file}.png"
83
+ filepath = os.path.join(output_dir, filename)
84
+ plt.savefig(filepath, bbox_inches='tight')
85
+ plt.close()
86
+
87
+ img1 = cv2.imread("data/"+f"{file}.png")
88
+ img2 = cv2.imread("swatches.png")
89
+ if img1.shape[1] != img2.shape[1]:
90
+ max_width = max(img1.shape[1], img2.shape[1])
91
+ img1 = cv2.resize(img1, (max_width, img1.shape[0]))
92
+ img2 = cv2.resize(img2, (max_width, img2.shape[0]))
93
+
94
+ merged_image = cv2.vconcat([img1, img2])
95
+ cv2.imwrite(filepath, merged_image)
96
+ file += 1
97
+
98
+ gold_output = {
99
+ "id": filename,
100
+ "colours_present": gold_answer,
101
+ "num_objects": n
102
+ }
103
+ data.append(gold_output)
104
+
105
+
106
+ if append:
107
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
108
+ old_data = json.load(f)
109
+ old_data.extend(data)
110
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
111
+ json.dump(old_data, f, indent=2)
112
+ else:
113
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
114
+ json.dump(data, f, indent=2)
115
+
116
+
117
+
118
+ # # Example usage
119
+ # generate_shapes(10, 'shapes.png')
120
+ if __name__ == "__main__":
121
+ # Parse command line arguments
122
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
123
+ parser.add_argument(
124
+ '--num_images',
125
+ type=int,
126
+ help='Number of images to generate',
127
+ default=1
128
+ )
129
+ parser.add_argument(
130
+ '--num_sizes',
131
+ nargs='*',
132
+ type=int,
133
+ help='List of count of objects',
134
+ default=[5]
135
+ )
136
+ parser.add_argument(
137
+ '--file',
138
+ type=int,
139
+ help='Starting file number',
140
+ default=1
141
+ )
142
+ args = parser.parse_args()
143
+ file = args.file
144
+ num_object_list = args.num_sizes
145
+ append = (file != 1)
146
+ generate_shapes(args.num_images, num_object_list , file)
colours_present/swatches.png ADDED

Git LFS Details

  • SHA256: 0e4f54072d7925f22d0ae80efa52d3eb47e1d929fe515d850bbbd6441d304936
  • Pointer size: 130 Bytes
  • Size of remote file: 21.4 kB
comparing_size/script.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+
7
+ def create_images(num_images, num_objects_list , file):
8
+ # Ensure the output directory exists
9
+ output_dir = os.path.join(os.getcwd(), "data")
10
+ if not os.path.exists(output_dir):
11
+ os.makedirs(output_dir)
12
+
13
+ data = []
14
+
15
+ append = (file != 1)
16
+ for num_objects in num_objects_list:
17
+ dpi = 100 # Dots per inch
18
+ width_inches = 1 # 100 pixels
19
+ height_inches = num_objects + 1 # 100 pixels per row
20
+ for img_index in range(num_images):
21
+ fig, ax = plt.subplots(figsize=(width_inches, height_inches), dpi=dpi)
22
+ image_data = []
23
+ for i in range (num_objects):
24
+ y = num_objects - i - 1
25
+ while True:
26
+ radius1 = random.uniform(0.05, 0.2)
27
+ radius2 = random.uniform(0.05, 0.2)
28
+ if abs(radius1 - radius2) >= 0.05:
29
+ break
30
+
31
+ if radius1 > radius2:
32
+ image_data.append("Blue")
33
+ else:
34
+ image_data.append("Green")
35
+ # Ensure the circles do not overlap by adjusting positions
36
+ x1, x2 = 0.25, 0.75
37
+
38
+ # Add circles to the plot
39
+ circle1 = plt.Circle((x1, y), radius1, color='blue', fill=True)
40
+ circle2 = plt.Circle((x2, y), radius2, color='green', fill=True)
41
+ ax.add_patch(circle1)
42
+ ax.add_patch(circle2)
43
+
44
+ # if i < num_objects -1:
45
+ ax.plot([0, 1], [y - 0.5, y - 0.5], color='black')
46
+
47
+ ax.set_xlim(0, 1)
48
+ ax.set_ylim(-0.6, num_objects - 0.5)
49
+ ax.set_aspect('equal')
50
+ ax.axis('off')
51
+
52
+ image_filename = f"{file}.png"
53
+ file += 1
54
+ image_path = os.path.join(output_dir, image_filename)
55
+ plt.savefig(image_path, bbox_inches='tight', dpi=dpi)
56
+ plt.close(fig)
57
+
58
+
59
+
60
+ # Store the number of objects in the image_data dictionary
61
+ gold_output = {
62
+ "id": image_filename,
63
+ "Gold_output": image_data,
64
+ "Rows" : num_objects
65
+ }
66
+ data.append(gold_output)
67
+
68
+ if append:
69
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
70
+ old_data = json.load(f)
71
+ old_data.extend(data)
72
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
73
+ json.dump(old_data, f, indent=2)
74
+ else:
75
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
76
+ json.dump(data, f, indent=2)
77
+
78
+ if __name__ == "__main__":
79
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
80
+ parser.add_argument(
81
+ '--num_images',
82
+ type=int,
83
+ help='Number of images to generate',
84
+ default=1
85
+ )
86
+ parser.add_argument(
87
+ '--num_sizes',
88
+ nargs='*',
89
+ type=int,
90
+ help='List of number of rows',
91
+ default=[5]
92
+ )
93
+ parser.add_argument(
94
+ '--file',
95
+ type=int,
96
+ help='Starting file number',
97
+ default=1
98
+ )
99
+ args = parser.parse_args()
100
+ file = args.file
101
+ num_object_list = args.num_sizes
102
+ append = (file != 1)
103
+ create_images(args.num_images, num_object_list , file)
count_coloured_circles/script.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+
7
+ def create_images(num_images, num_objects_list , file):
8
+ # Ensure that the directory exists
9
+ # output_dir = "./data"
10
+ output_dir = os.path.join(os.getcwd(), "data")
11
+ if not os.path.exists(output_dir):
12
+ os.makedirs(output_dir)
13
+
14
+ data = []
15
+ image_width, image_height = 500, 300
16
+ append = (file != 1)
17
+ for num_objects in num_objects_list:
18
+ max_obj = 2*num_objects
19
+ for img_index in range(num_images):
20
+ # Create a blank white image
21
+ image = Image.new("RGB", (image_width, image_height), "white")
22
+ draw = ImageDraw.Draw(image)
23
+
24
+ # List to hold positions of circles
25
+ positions = []
26
+
27
+ # Randomly select a radius for each circle
28
+ radii = [random.randint(10, 20) for _ in range(max_obj)]
29
+
30
+ # Generate non-overlapping positions for the circles
31
+ while len(positions) < max_obj:
32
+ x = random.randint(max(radius for radius in radii), image_width - max(radius for radius in radii))
33
+ y = random.randint(max(radius for radius in radii), image_height - max(radius for radius in radii))
34
+
35
+ # Check if the new circle overlaps or touches any existing circles
36
+ overlap = False
37
+ for (px, py, r) in positions:
38
+ distance = ((px - x) ** 2 + (py - y) ** 2) ** 0.5
39
+ if distance < r + max(radii):
40
+ overlap = True
41
+ break
42
+
43
+ if not overlap:
44
+ radius = radii[len(positions)]
45
+ positions.append((x, y, radius))
46
+
47
+ # Draw the circles
48
+ red_circle = num_objects
49
+ indices = random.sample(range(0, max_obj), num_objects)
50
+ for i, (x, y, radius) in enumerate(positions):
51
+ color = ""
52
+ if i in indices:
53
+ color = "red"
54
+ # draw.ellipse([x - radius, y - radius, x + radius, y + radius], fill="black")
55
+ #draw a random colored circle from red blue green yellow
56
+ else:
57
+ colors = ["blue", "green", "yellow"]
58
+ color = random.choice(colors)
59
+ draw.ellipse([x - radius, y - radius, x + radius, y + radius], fill=color)
60
+
61
+
62
+ # Save the image with the filename `i.png`
63
+ image_filename = f"{file}.png"
64
+ file += 1
65
+ image_path = os.path.join(output_dir, image_filename)
66
+ image.save(image_path)
67
+
68
+ # Store the number of objects in the data dictionary
69
+ # data[image_filename] = {
70
+ # "num_objects": num_objects
71
+ # }
72
+ gold_output = {
73
+ "id": image_filename,
74
+ "num_objects": num_objects,
75
+ "red_circle": red_circle
76
+ }
77
+ data.append(gold_output)
78
+
79
+ # print(f"Image saved at: {image_path}")
80
+
81
+ if append:
82
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
83
+ old_data = json.load(f)
84
+ old_data.extend(data)
85
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
86
+ json.dump(old_data, f, indent=2)
87
+ else:
88
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
89
+ json.dump(data, f, indent=2)
90
+
91
+ if __name__ == "__main__":
92
+ # Parse command line arguments
93
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
94
+ parser.add_argument(
95
+ '--num_images',
96
+ type=int,
97
+ help='Number of images to generate',
98
+ default=1
99
+ )
100
+ parser.add_argument(
101
+ '--num_sizes',
102
+ nargs='*',
103
+ type=int,
104
+ help='List of count of circles',
105
+ default=[5]
106
+ )
107
+ parser.add_argument(
108
+ '--file',
109
+ type=int,
110
+ help='Starting file number',
111
+ default=1
112
+ )
113
+ args = parser.parse_args()
114
+ file = args.file
115
+ num_object_list = args.num_sizes
116
+ append = (file != 1)
117
+ create_images(args.num_images, num_object_list , file)
counting_circles/script.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+
7
+ def create_images(num_images, num_objects_list , file):
8
+ # Ensure that the directory exists
9
+ # output_dir = "./data"
10
+ output_dir = os.path.join(os.getcwd(), "data")
11
+ if not os.path.exists(output_dir):
12
+ os.makedirs(output_dir)
13
+
14
+ data = []
15
+ image_width, image_height = 500, 300
16
+ append = (file != 1)
17
+ for num_objects in num_objects_list:
18
+ for img_index in range(num_images):
19
+ # Create a blank white image
20
+ image = Image.new("RGB", (image_width, image_height), "white")
21
+ draw = ImageDraw.Draw(image)
22
+
23
+ # List to hold positions of circles
24
+ positions = []
25
+
26
+ # Randomly select a radius for each circle
27
+ radii = [random.randint(10, 30) for _ in range(num_objects)]
28
+
29
+ # Generate non-overlapping positions for the circles
30
+ while len(positions) < num_objects:
31
+ x = random.randint(max(radius for radius in radii), image_width - max(radius for radius in radii))
32
+ y = random.randint(max(radius for radius in radii), image_height - max(radius for radius in radii))
33
+
34
+ # Check if the new circle overlaps or touches any existing circles
35
+ overlap = False
36
+ for (px, py, r) in positions:
37
+ distance = ((px - x) ** 2 + (py - y) ** 2) ** 0.5
38
+ if distance < r + max(radii):
39
+ overlap = True
40
+ break
41
+
42
+ if not overlap:
43
+ radius = radii[len(positions)]
44
+ positions.append((x, y, radius))
45
+
46
+ # Draw the circles
47
+ for (x, y, radius) in positions:
48
+ draw.ellipse([x - radius, y - radius, x + radius, y + radius], fill="black")
49
+
50
+ # Save the image with the filename `i.png`
51
+ image_filename = f"{file}.png"
52
+ file += 1
53
+ image_path = os.path.join(output_dir, image_filename)
54
+ image.save(image_path)
55
+
56
+ # Store the number of objects in the data dictionary
57
+ # data[image_filename] = {
58
+ # "num_objects": num_objects
59
+ # }
60
+ gold_output = {
61
+ "id": image_filename,
62
+ "num_objects": num_objects
63
+ }
64
+ data.append(gold_output)
65
+
66
+ # print(f"Image saved at: {image_path}")
67
+
68
+ if append:
69
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
70
+ old_data = json.load(f)
71
+ old_data.extend(data)
72
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
73
+ json.dump(old_data, f, indent=2)
74
+ else:
75
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
76
+ json.dump(data, f, indent=2)
77
+
78
+ if __name__ == "__main__":
79
+ # Parse command line arguments
80
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
81
+ parser.add_argument(
82
+ '--num_images',
83
+ type=int,
84
+ help='Number of images to generate',
85
+ default=1
86
+ )
87
+ parser.add_argument(
88
+ '--num_sizes',
89
+ nargs='*',
90
+ type=int,
91
+ help='List of count of circles',
92
+ default=[5]
93
+ )
94
+ parser.add_argument(
95
+ '--file',
96
+ type=int,
97
+ help='Starting file number',
98
+ default=1
99
+ )
100
+ args = parser.parse_args()
101
+ file = args.file
102
+ num_object_list = args.num_sizes
103
+ append = (file != 1)
104
+ create_images(args.num_images, num_object_list , file)
counting_locations/script.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ from PIL import Image, ImageDraw
4
+ import random
5
+ import argparse
6
+
7
+ # Function to draw an object
8
+ def draw_object(draw, position, color):
9
+ x, y = position
10
+ size = 30
11
+ draw.ellipse([x, y, x + size, y + size], fill=color)
12
+
13
+ def create_images(num_images, num_objects_list , file):
14
+ append = (file != 1)
15
+ data = []
16
+ for num_objects in num_objects_list:
17
+ print(f"Creating {num_images} images with {num_objects} objects...")
18
+ max_obj = 2*num_objects
19
+ for i in range(num_images):
20
+ # Image dimensions
21
+ width, height = 500, 300
22
+
23
+ # Create a blank image with a white background
24
+ image = Image.new("RGB", (width, height), "white")
25
+ draw = ImageDraw.Draw(image)
26
+
27
+ # Draw a simple table (a rectangle)
28
+ table_top_left = (10, 140)
29
+ table_bottom_right = (width-10, 160)
30
+ draw.rectangle([table_top_left, table_bottom_right], fill="brown")
31
+
32
+ # Randomly generate positions for objects
33
+ positions = []
34
+ num_over_table = 0
35
+ num_under_table = 0
36
+ for i in range(max_obj):
37
+ while True:
38
+ # Randomly decide whether the object is over or under the table
39
+ if i < num_objects:
40
+ # Over the table (above the table's top edge)
41
+ x = random.randint(10, width - 30)
42
+ y = random.randint(0, table_top_left[1] - 40)
43
+ if not any(abs(x - px) < 35 and abs(y - py) < 35 for px, py in positions):
44
+ positions.append((x, y))
45
+ num_over_table += 1
46
+ break
47
+
48
+ else:
49
+ # Under the table (below the table's bottom edge)
50
+ x = random.randint(10, width - 30)
51
+ y = random.randint(table_bottom_right[1] + 10, height - 40)
52
+ if not any(abs(x - px) < 35 and abs(y - py) < 35 for px, py in positions):
53
+ positions.append((x, y))
54
+ num_under_table += 1
55
+ break
56
+
57
+
58
+ # Draw the objects on the image
59
+ for pos in positions:
60
+ draw_object(draw, pos, color=random.choice(["red", "blue", "green", "yellow"]))
61
+
62
+ # Save the image with numerical naming in the ./data folder
63
+ image_filename = f"{file}.png"
64
+ file += 1
65
+ image_path = os.path.join(output_dir, image_filename)
66
+ image.save(image_path)
67
+
68
+ # Generate a random "gold output" for demonstration purposes
69
+ gold_output = {
70
+ "id": image_filename,
71
+ "num_objects_over_table": num_over_table,
72
+ "num_objects_under_table": num_under_table
73
+ # "object_positions": positions
74
+ }
75
+
76
+ # Add the filename and gold output to the data dictionary
77
+ data.append(gold_output)
78
+
79
+ if append:
80
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
81
+ old_data = json.load(f)
82
+ old_data.extend(data)
83
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
84
+ json.dump(old_data, f, indent=2)
85
+ else:
86
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
87
+ json.dump(data, f, indent=2)
88
+
89
+ print(f"Images saved in {output_dir} and data written to data.json.")
90
+
91
+
92
+ if __name__ == "__main__":
93
+
94
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
95
+ parser.add_argument(
96
+ '--num_images',
97
+ type=int,
98
+ help='Number of images to generate',
99
+ default=1
100
+ )
101
+ parser.add_argument(
102
+ '--num_sizes',
103
+ nargs='*',
104
+ type=int,
105
+ help='List of n values',
106
+ default=[5 , 3]
107
+ )
108
+ parser.add_argument(
109
+ '--file',
110
+ type=int,
111
+ help='Starting file number',
112
+ default=1
113
+ )
114
+ args = parser.parse_args()
115
+ file = args.file
116
+ num_object_list = args.num_sizes
117
+ # print(num_object_list)
118
+ # Create images with the specified number of objects
119
+ # Directory to save images
120
+ output_dir = os.path.join(os.getcwd(), "data")
121
+ if not os.path.exists(output_dir):
122
+ os.makedirs(output_dir)
123
+
124
+ create_images(args.num_images, num_object_list , file)
counting_shapes/script.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+
7
+ num_circle = 0
8
+ num_triangle = 0
9
+ num_square = 0
10
+
11
+ def random_shape(draw, shape_type, x, y, size):
12
+ """
13
+ Draw a random shape on the provided image.
14
+ """
15
+ global num_circle, num_square, num_triangle, num_star
16
+ if shape_type == "circle":
17
+ draw.ellipse([x - size, y - size, x + size, y + size], fill="black")
18
+ num_circle +=1
19
+ elif shape_type == "square":
20
+ draw.rectangle([x - size, y - size, x + size, y + size], fill="black")
21
+ num_square +=1
22
+ elif shape_type == "triangle":
23
+ points = [
24
+ (x, y - size), # Top
25
+ (x - size, y + size), # Bottom left
26
+ (x + size, y + size), # Bottom right
27
+ ]
28
+ draw.polygon(points, fill="black")
29
+ num_triangle +=1
30
+
31
+ def create_images(num_images, num_objects_list , file):
32
+ # Ensure the output directory exists
33
+ global num_circle, num_square, num_triangle, num_star
34
+ output_dir = os.path.join(os.getcwd(), "data")
35
+ if not os.path.exists(output_dir):
36
+ os.makedirs(output_dir)
37
+
38
+ data = []
39
+ image_width, image_height = 500, 300
40
+ append = (file != 1)
41
+ for num_objects in num_objects_list:
42
+ for img_index in range(num_images):
43
+ # Create a blank white image
44
+ image = Image.new("RGB", (image_width, image_height), "white")
45
+ draw = ImageDraw.Draw(image)
46
+
47
+ # List to hold positions and sizes of shapes
48
+ shapes = []
49
+ num_circle =0
50
+ num_triangle = 0
51
+ num_star = 0
52
+ num_square = 0
53
+
54
+
55
+ # Possible shape types
56
+ shape_types = ["circle", "square", "triangle"]
57
+
58
+ while len(shapes) < num_objects:
59
+ shape_type = random.choice(shape_types)
60
+ size = random.randint(10, 20)
61
+ x = random.randint(size+50, image_width - size - 50)
62
+ y = random.randint(size + 50, image_height - size - 50)
63
+
64
+ # Check if the new shape overlaps or touches any existing shapes
65
+ overlap = False
66
+ for (sx, sy, ssize,_) in shapes:
67
+ distance = ((sx - x) ** 2 + (sy - y) ** 2) ** 0.5
68
+ if distance < (ssize + size)*1.5:
69
+ overlap = True
70
+ break
71
+
72
+ if not overlap:
73
+ shapes.append((x, y, size, shape_type))
74
+ # print(shapes)
75
+ # Draw the shapes
76
+ for (x, y, size, shape_type) in shapes:
77
+ random_shape(draw, shape_type, x, y, size)
78
+
79
+ # Save the image with the filename `i.png`
80
+ image_filename = f"{file}.png"
81
+ file += 1
82
+ image_path = os.path.join(output_dir, image_filename)
83
+ image.save(image_path)
84
+
85
+ # Store the number of objects in the data dictionary
86
+ gold_output = {
87
+ "id": image_filename,
88
+ "circles" : num_circle,
89
+ "squares" : num_square,
90
+ "triangles" : num_triangle
91
+ }
92
+ data.append(gold_output)
93
+
94
+ # Save the data to a JSON file
95
+ if append:
96
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
97
+ old_data = json.load(f)
98
+ old_data.extend(data)
99
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
100
+ json.dump(old_data, f, indent=2)
101
+ else:
102
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
103
+ json.dump(data, f, indent=2)
104
+
105
+ if __name__ == "__main__":
106
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
107
+ parser.add_argument(
108
+ '--num_images',
109
+ type=int,
110
+ help='Number of images to generate',
111
+ default=1
112
+ )
113
+ parser.add_argument(
114
+ '--num_sizes',
115
+ nargs='*',
116
+ type=int,
117
+ help='List of num shapes',
118
+ default=[5]
119
+ )
120
+ parser.add_argument(
121
+ '--file',
122
+ type=int,
123
+ help='Starting file number',
124
+ default=1
125
+ )
126
+ args = parser.parse_args()
127
+ file = args.file
128
+ num_object_list = args.num_sizes
129
+ # print(num_object_list)
130
+ # Create images with the specified number of objects
131
+ create_images(args.num_images, num_object_list , file)
cross_and_knots/script.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ import random
4
+ import os
5
+ import json
6
+ import argparse
7
+
8
+
9
+ def create_grid_with_crosses(n, k , output_dir):
10
+ # Create a figure and axis
11
+ global file
12
+
13
+ fig, ax = plt.subplots()
14
+
15
+ # Set the limits of the grid
16
+ ax.set_xlim(0, n)
17
+ ax.set_ylim(0, n)
18
+
19
+ # Disable axis labels and ticks
20
+ ax.set_xticks(np.arange(0, n+1, 1))
21
+ ax.set_yticks(np.arange(0, n+1, 1))
22
+ ax.grid(True)
23
+ ax.tick_params(left=False, bottom=False, labelleft=False, labelbottom=False)
24
+
25
+ # Randomly select k unique cells for crosses
26
+ if (k < n*n):
27
+ crosses = set()
28
+ while len(crosses) < k:
29
+ cross_position = (random.randint(0, n-1), random.randint(0, n-1))
30
+ crosses.add(cross_position)
31
+
32
+ # Store cross positions in a list
33
+ cross_list = list(crosses)
34
+ else:
35
+ cross_list = []
36
+ crosses = set()
37
+ for i in range(n):
38
+ for j in range(n):
39
+ cross_list.append((i,j))
40
+ crosses.add((i,j))
41
+
42
+
43
+ # Label the cells (i,j) that don't have crosses
44
+ for i in range(n):
45
+ for j in range(n):
46
+ if (i, j) not in crosses:
47
+ label = f"({i},{j})"
48
+ ax.text(j + 0.5, n - i - 0.5, label, va='center', ha='center', fontsize=8, color='blue')
49
+ else:
50
+ ax.text(j + 0.5, n - i - 0.5, 'X', va='center', ha='center', fontsize=25, color='black')
51
+
52
+ # Draw grid lines
53
+ ax.set_xticks(np.arange(0, n+1, 1), minor=False)
54
+ ax.set_yticks(np.arange(0, n+1, 1), minor=False)
55
+ plt.grid(True)
56
+
57
+ # Show the plot
58
+ plt.gca().set_aspect('equal', adjustable='box')
59
+ # plt.show()
60
+ image_filename = f"{file}.png"
61
+ file += 1
62
+ image_path = os.path.join(output_dir, image_filename)
63
+ plt.savefig(image_path)
64
+ plt.close()
65
+
66
+ return cross_list
67
+
68
+
69
+ def is_safe_from_cross(crosses, i, j, n):
70
+ """Checks if all non-diagonal adjacent cells of (i, j) do not contain crosses."""
71
+ # Define directions for non-diagonal moves (up, down, left, right)
72
+ directions = [(-1, 0), (1, 0), (0, -1), (0, 1) , (0,0)]
73
+
74
+ for di, dj in directions:
75
+ ni, nj = i + di, j + dj
76
+ # Check if the adjacent cell is within bounds and contains a cross
77
+ if 0 <= ni < n and 0 <= nj < n:
78
+ if (ni, nj) in crosses:
79
+ return False
80
+ return True
81
+
82
+ if __name__ == "__main__":
83
+
84
+ parser = argparse.ArgumentParser(description="Generate data for cross and knots")
85
+ parser.add_argument(
86
+ '--num_images',
87
+ type=int,
88
+ help='Number of images to generate',
89
+ default=1
90
+ )
91
+ parser.add_argument(
92
+ '--num_sizes',
93
+ nargs='*',
94
+ help='List of n values (grid size , number of crosses) to generate',
95
+ default=[3 , 1]
96
+ )
97
+ parser.add_argument(
98
+ '--grid_size',
99
+ type=int,
100
+ help='Grid size',
101
+ default=6
102
+ )
103
+ parser.add_argument(
104
+ '--file',
105
+ type=int,
106
+ help='Output directory',
107
+ default=1
108
+ )
109
+ args = parser.parse_args()
110
+ num_images = args.num_images
111
+ num_sizes = args.num_sizes
112
+ file = args.file
113
+ append = (file != 1)
114
+ # num_images = int(sys.argv[1])
115
+ # num_sizes = sys.argv[2:]
116
+ # # print(num_images)
117
+ # file = 1
118
+ data = []
119
+ output_dir = os.path.join(os.getcwd(), "data")
120
+ if not os.path.exists(output_dir):
121
+ os.makedirs(output_dir)
122
+
123
+ for j in range(0, len(num_sizes)):
124
+ for i in range(num_images):
125
+ n = args.grid_size
126
+ crosses = int(num_sizes[j])
127
+ # print(n,k)
128
+ cross_positions = create_grid_with_crosses(args.grid_size, crosses , output_dir)
129
+
130
+ safe_cells = []
131
+ for k in range(n):
132
+ for l in range(n):
133
+ if is_safe_from_cross(set(cross_positions), k, l, n):
134
+ safe_cells.append((k, l))
135
+
136
+ data.append({
137
+ "id" : f"{file-1}.png",
138
+ "n" : args.grid_size,
139
+ "crosses" : crosses,
140
+ "cross_positions" : cross_positions,
141
+ "gold_output" : safe_cells
142
+ })
143
+ # Print the list of cross positions
144
+ # print("Cross positions:", cross_positions)
145
+ if append:
146
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
147
+ old_data = json.load(f)
148
+ old_data.extend(data)
149
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
150
+ json.dump(old_data, f, indent=2)
151
+ else:
152
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
153
+ json.dump(data, f, indent=2)
154
+
155
+
graph_counting/script.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import networkx as nx
2
+ import matplotlib.pyplot as plt
3
+ import random
4
+ import argparse
5
+ import os
6
+ import json
7
+
8
+
9
+ def generate_graph(num_nodes, num_edges):
10
+ # Create an empty graph
11
+ G = nx.Graph()
12
+
13
+ # Add nodes to the graph
14
+ G.add_nodes_from(range(num_nodes))
15
+
16
+ # Add edges to the graph
17
+ possible_edges = [(i, j) for i in range(num_nodes) for j in range(i+1, num_nodes)]
18
+ random_edges = random.sample(possible_edges, num_edges)
19
+ G.add_edges_from(random_edges)
20
+
21
+ return G
22
+
23
+ def draw_graph(G, idx):
24
+
25
+ global file
26
+ # Draw the graph
27
+ plt.figure(figsize=(12, 12))
28
+ pos = nx.spring_layout(G) # Layout for visualization
29
+ nx.draw(G, pos, with_labels=False, node_color='lightblue', edge_color='gray', node_size=2000, font_size=15)
30
+ image_filename = f"{file}.png"
31
+ file += 1
32
+ image_path = os.path.join(output_dir, image_filename)
33
+ plt.savefig(image_path)
34
+ plt.close()
35
+
36
+ # Parameters: number of nodes and number of edges
37
+
38
+
39
+ # num_nodes = 10
40
+
41
+ # # Generate and draw the graph
42
+ # for i in range(1, 11):
43
+ # num_edges = random.randint(10, 15)
44
+ # G = generate_graph(num_nodes, num_edges)
45
+ # draw_graph(G, idx=i)
46
+
47
+ if __name__ == '__main__':
48
+ output_dir = os.path.join(os.getcwd(), "data")
49
+ if not os.path.exists(output_dir):
50
+ os.makedirs(output_dir)
51
+
52
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
53
+ parser.add_argument(
54
+ '--num_images',
55
+ type=int,
56
+ help='Number of images to generate',
57
+ default=1
58
+ )
59
+ parser.add_argument(
60
+ '--num_sizes',
61
+ nargs='*',
62
+ type = int,
63
+ help='List of num of nodes',
64
+ default=[5]
65
+ )
66
+ parser.add_argument(
67
+ '--file',
68
+ type=int,
69
+ help='Starting file number',
70
+ default=1
71
+ )
72
+ args = parser.parse_args()
73
+ file = args.file
74
+ num_nodes = args.num_sizes
75
+ num_images = args.num_images
76
+ append = (file != 1)
77
+ data = []
78
+
79
+ for num_node in num_nodes:
80
+ for i in range(num_images):
81
+ if num_node == 1:
82
+ num_edges = 0
83
+ else:
84
+ min_edge = min((num_node*(num_node-1))//2, (num_node+5))
85
+ num_edges = random.randint(num_node-1, min_edge)
86
+ G = generate_graph(num_node, num_edges)
87
+ draw_graph(G, idx=i)
88
+ data.append({
89
+ "id": f"{file-1}.png",
90
+ "num_nodes": num_node,
91
+ "num_edges": num_edges
92
+ })
93
+ if append:
94
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
95
+ old_data = json.load(f)
96
+ old_data.extend(data)
97
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
98
+ json.dump(old_data, f, indent=2)
99
+ else:
100
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
101
+ json.dump(data, f, indent=2)
grid_path/script.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+ import random
3
+ import argparse
4
+ import os
5
+ import json
6
+
7
+ def create_grid_image(n, m, image_size=800):
8
+ global file, output_dir
9
+ # Create a new image with white background
10
+ img = Image.new('RGB', (image_size, image_size), 'white')
11
+ draw = ImageDraw.Draw(img)
12
+
13
+ image_list = []
14
+ grid = []
15
+
16
+ # Calculate cell size based on grid size
17
+ cell_size = image_size // n
18
+ border_color = 'black'
19
+ shape_colors = ['red', 'green', 'blue', 'purple']
20
+ # shape_colors = ['red']
21
+
22
+ # Load a default font with a larger size for better visibility
23
+ font_size = cell_size // 2
24
+ font = ImageFont.truetype("arial.ttf", font_size)
25
+
26
+ # Draw grid borders
27
+ for i in range(n + 1):
28
+ draw.line([(i * cell_size, 0), (i * cell_size, image_size)], fill=border_color, width=2)
29
+ draw.line([(0, i * cell_size), (image_size, i * cell_size)], fill=border_color, width=2)
30
+
31
+ # Add shapes inside each cell
32
+ for i in range(n):
33
+ row = []
34
+ for j in range(n):
35
+ shape_type = random.choice(['circle', 'square', 'triangle'])
36
+ shape_color = random.choice(shape_colors)
37
+ top_left = (j * cell_size + 5, i * cell_size + 5)
38
+ bottom_right = ((j + 1) * cell_size - 5, (i + 1) * cell_size - 5)
39
+
40
+ if shape_type == 'circle':
41
+ draw.ellipse([top_left, bottom_right], fill=shape_color)
42
+ row.append('circle')
43
+ elif shape_type == 'square':
44
+ draw.rectangle([top_left, bottom_right], fill=shape_color)
45
+ row.append('square')
46
+ elif shape_type == 'triangle':
47
+ mid_x = (top_left[0] + bottom_right[0]) / 2
48
+ draw.polygon([top_left, (bottom_right[0], top_left[1]), (mid_x, bottom_right[1])], fill=shape_color)
49
+ row.append('triangle')
50
+ grid.append(row)
51
+ # print(grid)
52
+ # Generate a random path of length m
53
+ path = [(random.randint(0, n - 1), random.randint(0, n - 1))]
54
+ while len(path) < m:
55
+ last_x, last_y = path[-1]
56
+ possible_moves = [(last_x + dx, last_y + dy) for dx, dy in [(0, 1), (1, 0), (0, -1), (-1, 0)]]
57
+ valid_moves = [(x, y) for x, y in possible_moves if 0 <= x < n and 0 <= y < n and (x, y) not in path]
58
+ if valid_moves:
59
+ path.append(random.choice(valid_moves))
60
+ else:
61
+ break # No more moves possible
62
+
63
+ # Draw the path with arrows and mark the start and end cells
64
+ arrow_dict = {(1, 0): '→', (0, 1): '↓', (-1, 0): '←', (0, -1): '↑'}
65
+ # print(path)
66
+ for index in range(len(path) - 1):
67
+ x1, y1 = path[index]
68
+ x2, y2 = path[index + 1]
69
+ start = (x1 * cell_size + cell_size // 2, y1 * cell_size + cell_size // 2)
70
+ end = (x2 * cell_size + cell_size // 2, y2 * cell_size + cell_size // 2)
71
+ draw.line([start, end], fill='black', width=4)
72
+ # print(x1 , y1)
73
+ image_list.append(grid[y1][x1])
74
+ # Draw arrow in the middle of the line
75
+ dx, dy = x2 - x1, y2 - y1
76
+ if (dx, dy) in arrow_dict:
77
+ arrow = arrow_dict[(dx, dy)]
78
+ arrow_position = ((start[0] + end[0]) // 2, (start[1] + end[1]) // 2 - cell_size*0.045)
79
+ # print(arrow_position , start , end)
80
+ draw.text(arrow_position, arrow, fill='black', font=font, anchor="mm")
81
+
82
+ # Label the start and end cells with larger and bolder text
83
+ start_x, start_y = path[0]
84
+ end_x, end_y = path[-1]
85
+ draw.text((start_x * cell_size + cell_size // 2, start_y * cell_size + cell_size // 2), 'S', fill='black', font=font, anchor="mm")
86
+ draw.text((end_x * cell_size + cell_size // 2, end_y * cell_size + cell_size // 2), 'E', fill='black', font=font, anchor="mm")
87
+
88
+ image_list.append(grid[end_y][end_x])
89
+ # Save the image
90
+ # img.save('grid_image_with_path.png')
91
+ image_filename = f"{file}.png"
92
+ file += 1
93
+ image_path = os.path.join(output_dir, image_filename)
94
+ img.save(image_path)
95
+
96
+ return image_list
97
+
98
+
99
+ if __name__ == "__main__":
100
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
101
+ parser.add_argument(
102
+ '--num_images',
103
+ type=int,
104
+ help='Number of images to generate',
105
+ default=1
106
+ )
107
+ parser.add_argument(
108
+ '--num_sizes',
109
+ nargs='*',
110
+ help='List of n values',
111
+ default=[5 , 3]
112
+ )
113
+ parser.add_argument(
114
+ '--grid_size',
115
+ type=int,
116
+ help='Grid size',
117
+ default=6
118
+ )
119
+ parser.add_argument(
120
+ '--file',
121
+ type=int,
122
+ help='Starting file number',
123
+ default=1
124
+ )
125
+ args = parser.parse_args()
126
+ file = args.file
127
+ num_sizes = args.num_sizes
128
+ append = (file != 1)
129
+ data = []
130
+ output_dir = os.path.join(os.getcwd(), "data")
131
+ if not os.path.exists(output_dir):
132
+ os.makedirs(output_dir)
133
+
134
+ for j in range(0, len(num_sizes)):
135
+ for i in range(args.num_images):
136
+ rows = args.grid_size
137
+ path_size = int(num_sizes[j])
138
+ image_list = create_grid_image(rows, path_size)
139
+ # print(grid)
140
+ data.append({
141
+ 'id': f"{file-1}.png",
142
+ 'rows': rows,
143
+ 'path_size': path_size,
144
+ 'gold_output': image_list
145
+ })
146
+
147
+ if append:
148
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
149
+ old_data = json.load(f)
150
+ old_data.extend(data)
151
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
152
+ json.dump(old_data, f, indent=2)
153
+ else:
154
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
155
+ json.dump(data, f, indent=2)
identifying_shapes/script.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import matplotlib.patches as mp
3
+ import random
4
+ import os
5
+ import json
6
+ import sys
7
+ import argparse
8
+
9
+
10
+ def create_images(num_images, num_objects_list, items_list):
11
+ # Ensure the output directory exists
12
+ output_dir = os.path.join(os.getcwd(), "data")
13
+ if not os.path.exists(output_dir):
14
+ os.makedirs(output_dir)
15
+
16
+ data = []
17
+
18
+ file = 1
19
+ for num_objects in num_objects_list:
20
+ dpi = 100 # Dots per inch
21
+ width_inches = 1 # 100 pixels
22
+ height_inches = num_objects # 100 pixels per row
23
+ for img_index in range(num_images):
24
+ fig, ax = plt.subplots(figsize=(width_inches, height_inches), dpi=dpi)
25
+ image_data = []
26
+ image_side = []
27
+ for i in range (num_objects):
28
+ shape, sides = random.choice(list(items_list.items()))
29
+ y = num_objects - i - 1
30
+ image_data.append(shape)
31
+ image_side.append(sides)
32
+ # Ensure the circles do not overlap by adjusting positions
33
+ # Add circles to the plot
34
+ if(shape == 'Circle'):
35
+ circle = mp.Circle((0.5, y), 0.3, color='blue', fill=True)
36
+ ax.add_patch(circle)
37
+ if(shape == 'Diamond'):
38
+ sq = mp.RegularPolygon((0.5, y), numVertices=4, radius=0.3, facecolor='green')
39
+ ax.add_patch(sq)
40
+ if(shape == 'Triangle'):
41
+ tri = mp.RegularPolygon((0.5, y), numVertices=3, radius=0.3, facecolor='red')
42
+ ax.add_patch(tri)
43
+ if(shape == 'Pentagon'):
44
+ pent = mp.RegularPolygon((0.5, y), numVertices=5, radius=0.3, facecolor='cyan')
45
+ ax.add_patch(pent)
46
+ if(shape == 'Hexagon'):
47
+ hex = mp.RegularPolygon((0.5, y), numVertices=6, radius=0.3, facecolor='magenta')
48
+ ax.add_patch(hex)
49
+
50
+ if i < num_objects -1:
51
+ ax.plot([0, 1], [y - 0.5, y - 0.5], color='black')
52
+
53
+ ax.set_xlim(0, 1)
54
+ ax.set_ylim(-0.5, num_objects - 0.5)
55
+ ax.set_aspect('equal')
56
+ ax.axis('off')
57
+
58
+ image_filename = f"{file}.png"
59
+ file += 1
60
+ image_path = os.path.join(output_dir, image_filename)
61
+ plt.savefig(image_path, bbox_inches='tight', dpi=dpi)
62
+ plt.close(fig)
63
+
64
+
65
+
66
+ # Store the number of objects in the image_data dictionary
67
+ gold_output = {
68
+ "id": image_filename,
69
+ "Gold_output": image_data,
70
+ "Gold_side": image_side,
71
+ "Rows" : num_objects
72
+ }
73
+ data.append(gold_output)
74
+
75
+ # Save the data to a JSON file
76
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as json_file:
77
+ json.dump(data, json_file, indent=4)
78
+
79
+ if __name__ == "__main__":
80
+ # Parse command line arguments
81
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
82
+ parser.add_argument(
83
+ '--num_images',
84
+ type=int,
85
+ help='Number of images to generate',
86
+ default=1
87
+ )
88
+ parser.add_argument(
89
+ '--num_sizes',
90
+ nargs='*',
91
+ type=int,
92
+ help='List of count of circles',
93
+ default=[5]
94
+ )
95
+ parser.add_argument(
96
+ '--file',
97
+ type=int,
98
+ help='Starting file number',
99
+ default=1
100
+ )
101
+ args = parser.parse_args()
102
+ file = args.file
103
+ num_object_list = args.num_sizes
104
+ append = (file != 1)
105
+ items_list = {'Circle':0, 'Triangle':3, 'Diamond':4, 'Pentagon':5, 'Hexagon':6}
106
+ create_images(args.num_images, num_object_list, items_list)
107
+ # print(num_object_list)
108
+ # Create images with the specified number of objects
inside_circles/script.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import PIL
3
+ from PIL import Image
4
+ import random
5
+ import numpy as np
6
+ import os
7
+ import json
8
+ import argparse
9
+
10
+ def generate_shapes(num_images, num_objects_list , file):
11
+ # Set up the plot
12
+
13
+ output_dir = os.path.join(os.getcwd(), "data")
14
+ input_dir = os.path.join(os.getcwd(), "background_image")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ append = (file != 1)
20
+
21
+ for n in num_objects_list:
22
+ for img_index in range(num_images):
23
+ fig, ax = plt.subplots()
24
+ ax.set_aspect('equal')
25
+ plt.axis('off')
26
+
27
+ # Adjust plot limits to prevent cutoff
28
+ plt.xlim(-0.7, 1.4)
29
+ plt.ylim(-0.7, 1.4)
30
+
31
+ # Generate random positions for the shapes
32
+ positions = []
33
+ radii = []
34
+ gold_answer = 0
35
+ for i in range(n):
36
+ x, y = random.uniform(0.1, 0.9), random.uniform(0.1, 0.9)
37
+ positions.append((x, y))
38
+ radius = random.uniform(0.1, 0.5)
39
+ radii.append(radius)
40
+
41
+ # Draw shapes and label them
42
+ cx, cy = random.uniform(0.1, 0.9), random.uniform(0.1, 0.9)
43
+ ax.add_patch(plt.Circle((cx, cy), 0.05, color='red'))
44
+ for i, (x, y) in enumerate(positions):
45
+ shape = plt.Circle((x, y), radii[i], color='black', fill=False)
46
+ ax.add_patch(shape)
47
+
48
+ if ((cx - x)**2 + (cy - y)**2)**0.5 < radii[i]:
49
+ gold_answer += 1
50
+
51
+ # Save the plot to a file
52
+ filename = f"{file}.png"
53
+ file += 1
54
+ filepath = os.path.join(output_dir, filename)
55
+ plt.savefig(filepath, bbox_inches='tight')
56
+ plt.close()
57
+ answer = False
58
+ if gold_answer == 0:
59
+ answer = False
60
+ else:
61
+ answer = True
62
+
63
+ gold_output = {
64
+ "id": filename,
65
+ "inside_circles": answer,
66
+ "num_circles": n
67
+ }
68
+ data.append(gold_output)
69
+
70
+
71
+ if append:
72
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
73
+ old_data = json.load(f)
74
+ old_data.extend(data)
75
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
76
+ json.dump(old_data, f, indent=2)
77
+ else:
78
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
79
+ json.dump(data, f, indent=2)
80
+
81
+
82
+
83
+ # # Example usage
84
+ # generate_shapes(10, 'shapes.png')
85
+ if __name__ == "__main__":
86
+ # Parse command line arguments
87
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
88
+ parser.add_argument(
89
+ '--num_images',
90
+ type=int,
91
+ help='Number of images to generate',
92
+ default=1
93
+ )
94
+ parser.add_argument(
95
+ '--num_sizes',
96
+ nargs='*',
97
+ type=int,
98
+ help='List of count of objects',
99
+ default=[5]
100
+ )
101
+ parser.add_argument(
102
+ '--file',
103
+ type=int,
104
+ help='Starting file number',
105
+ default=1
106
+ )
107
+ args = parser.parse_args()
108
+ file = args.file
109
+ num_object_list = args.num_sizes
110
+ append = (file != 1)
111
+ generate_shapes(args.num_images, num_object_list , file)
layered_colours/script.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ from itertools import combinations
3
+ import cv2
4
+ import random
5
+ import os
6
+ import json
7
+ import argparse
8
+ import numpy as np
9
+
10
+
11
+
12
+ def generate_depth_images(num_images , num_object_list , file , image_size=(500, 500)):
13
+ output_dir = os.path.join(os.getcwd(), "data")
14
+ if not os.path.exists(output_dir):
15
+ os.makedirs(output_dir)
16
+
17
+ data = []
18
+ append = (file != 1)
19
+
20
+ for n in num_object_list:
21
+ for _ in range(num_images):
22
+ colors = {'black', 'gray', 'brown', 'maroon', 'red', 'coral', 'tan', 'orange', 'ivory', 'goldenrod', 'yellow', 'green', 'olive', 'turquoise', 'skyblue', 'blue', 'lavender', 'purple', 'pink', 'fuchsia'}
23
+ colors_n = random.choice(list(combinations(colors, n)))
24
+ #print(colors_n)
25
+ random.shuffle(list(colors_n))
26
+
27
+ fig, ax = plt.subplots()
28
+ ax.set_aspect('equal')
29
+ plt.axis('off')
30
+
31
+ # Adjust plot limits to prevent cutoff
32
+ plt.xlim(-1.0, 1.0)
33
+ plt.ylim(-1.0, 1.0)
34
+
35
+ # Generate random positions for the shapes
36
+ radii = np.linspace(0.9, 0.05, n)
37
+
38
+ # Draw shapes and label them
39
+ cx, cy = 0.0, 0.0
40
+ for i in range(n):
41
+ shape = plt.Circle((cx, cy), radii[i], color=colors_n[i], ec='black', fill=True)
42
+ ax.add_patch(shape)
43
+
44
+ # Save the plot to a file
45
+ filename = f"{file}.png"
46
+ filepath = os.path.join(output_dir, filename)
47
+ plt.savefig(filepath, bbox_inches='tight')
48
+ plt.close()
49
+
50
+ img1 = cv2.imread("data/"+f"{file}.png")
51
+ img2 = cv2.imread("swatches.png")
52
+ if img1.shape[1] != img2.shape[1]:
53
+ max_width = max(img1.shape[1], img2.shape[1])
54
+ img1 = cv2.resize(img1, (max_width, img1.shape[0]))
55
+ img2 = cv2.resize(img2, (max_width, img2.shape[0]))
56
+
57
+ merged_image = cv2.vconcat([img1, img2])
58
+ cv2.imwrite(filepath, merged_image)
59
+ file += 1
60
+
61
+ gold_output = {
62
+ "id": filename,
63
+ "num_layers" : n,
64
+ "colors": colors_n[::-1],
65
+ }
66
+ data.append(gold_output)
67
+
68
+ if append:
69
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
70
+ old_data = json.load(f)
71
+ old_data.extend(data)
72
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
73
+ json.dump(old_data, f, indent=2)
74
+ else:
75
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
76
+ json.dump(data, f, indent=2)
77
+
78
+
79
+ # # Generate and display an example image
80
+ # n_shapes = 3
81
+ # image = generate_depth_images(n_shapes)
82
+ # image.show()
83
+
84
+ if __name__ == "__main__":
85
+ # Parse command line arguments
86
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
87
+ parser.add_argument(
88
+ '--num_images',
89
+ type=int,
90
+ help='Number of images to generate',
91
+ default=1
92
+ )
93
+ parser.add_argument(
94
+ '--num_sizes',
95
+ nargs='*',
96
+ type=int,
97
+ help='List of count of layers',
98
+ default=[5]
99
+ )
100
+ parser.add_argument(
101
+ '--file',
102
+ type=int,
103
+ help='Starting file number',
104
+ default=1
105
+ )
106
+ args = parser.parse_args()
107
+ file = args.file
108
+ num_object_list = args.num_sizes
109
+ append = (file != 1)
110
+ generate_depth_images(args.num_images, num_object_list , file)
layered_colours/swatches.png ADDED

Git LFS Details

  • SHA256: 0e4f54072d7925f22d0ae80efa52d3eb47e1d929fe515d850bbbd6441d304936
  • Pointer size: 130 Bytes
  • Size of remote file: 21.4 kB
layered_shapes/script.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+ import math
7
+
8
+
9
+
10
+ def generate_depth_images(num_images , num_object_list , file , image_size=(1800, 1800)):
11
+ output_dir = os.path.join(os.getcwd(), "data")
12
+ if not os.path.exists(output_dir):
13
+ os.makedirs(output_dir)
14
+
15
+ data = []
16
+ append = (file != 1)
17
+
18
+ for n in num_object_list:
19
+ for _ in range(num_images):
20
+ canvas = Image.new("RGB", image_size, (255, 255, 255))
21
+ draw = ImageDraw.Draw(canvas)
22
+ def color_distance(c1, c2):
23
+ return sum((a - b) ** 2 for a, b in zip(c1, c2))
24
+
25
+ def generate_distinct_colors(n, min_diff=500):
26
+ colors = []
27
+ while len(colors) < n:
28
+ new_color = (random.randint(50, 205), random.randint(50, 205), random.randint(50, 205))
29
+ if all(color_distance(new_color, c) > min_diff for c in colors):
30
+ colors.append(new_color)
31
+ return colors
32
+
33
+ colors = generate_distinct_colors(n)
34
+ # colors = [(random.randint(50, 255), random.randint(50, 255), random.randint(50, 255)) for _ in range(n)]
35
+ #shapes = [ 'triangle' , 'square' , 'pentagon', 'hexagon']
36
+ shapes = ['diamond', 'hexagon', 'octagon']
37
+
38
+ center_x, center_y = image_size[0] // 2, image_size[1] // 2 # Keep all shapes centered
39
+
40
+ def draw_polygon(sides, radius, center, color):
41
+ angle = 360 / sides
42
+ points = [
43
+ (
44
+ center[0] + radius * math.cos(math.radians(i * angle)),
45
+ center[1] + radius * math.sin(math.radians(i * angle))
46
+ )
47
+ for i in range(sides)
48
+ ]
49
+ draw.polygon(points, outline='black', fill=color)
50
+
51
+ order = []
52
+ prev_size = 800
53
+ for i in reversed(range(n)): # Draw from back to front
54
+
55
+ size = prev_size
56
+ shape_type = random.choice(shapes)
57
+ order.append(shape_type)
58
+
59
+ if shape_type == 'diamond':
60
+ draw_polygon(4 , size, (center_x, center_y), colors[i])
61
+ prev_size = size*math.cos(math.radians(45))
62
+ elif shape_type == 'circle':
63
+ draw_polygon(360, (size-((i/n)*200)), (center_x, center_y), colors[i])
64
+ prev_size = size
65
+ elif shape_type == 'octagon':
66
+ draw_polygon(8, size, (center_x, center_y), colors[i])
67
+ prev_size = size*math.cos(math.radians(22.5))
68
+ elif shape_type == 'hexagon':
69
+ draw_polygon(6, size, (center_x, center_y), colors[i])
70
+ prev_size = size*math.cos(math.radians(30))
71
+
72
+ #prev_size -= (200/n)
73
+
74
+
75
+ image_filename = f"{file}.png"
76
+ file += 1
77
+ image_path = os.path.join(output_dir, image_filename)
78
+ canvas.save(image_path)
79
+
80
+ reversed_order = order[::-1]
81
+
82
+ gold_output = {
83
+ "id": image_filename,
84
+ "num_layers" : n,
85
+ "order": reversed_order,
86
+ }
87
+ data.append(gold_output)
88
+
89
+ if append:
90
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
91
+ old_data = json.load(f)
92
+ old_data.extend(data)
93
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
94
+ json.dump(old_data, f, indent=2)
95
+ else:
96
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
97
+ json.dump(data, f, indent=2)
98
+
99
+
100
+ # # Generate and display an example image
101
+ # n_shapes = 3
102
+ # image = generate_depth_images(n_shapes)
103
+ # image.show()
104
+
105
+ if __name__ == "__main__":
106
+ # Parse command line arguments
107
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
108
+ parser.add_argument(
109
+ '--num_images',
110
+ type=int,
111
+ help='Number of images to generate',
112
+ default=1
113
+ )
114
+ parser.add_argument(
115
+ '--num_sizes',
116
+ nargs='*',
117
+ type=int,
118
+ help='List of count of layers',
119
+ default=[5]
120
+ )
121
+ parser.add_argument(
122
+ '--file',
123
+ type=int,
124
+ help='Starting file number',
125
+ default=1
126
+ )
127
+ args = parser.parse_args()
128
+ file = args.file
129
+ num_object_list = args.num_sizes
130
+ append = (file != 1)
131
+ generate_depth_images(args.num_images, num_object_list , file)
list_colours/script.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from itertools import combinations
2
+ import matplotlib.pyplot as plt
3
+ import PIL
4
+ from PIL import Image
5
+ import cv2
6
+ import random
7
+ import numpy as np
8
+ import os
9
+ import json
10
+ import argparse
11
+
12
+ def generate_shapes(num_images, num_objects_list , file):
13
+ # Set up the plot
14
+
15
+ output_dir = os.path.join(os.getcwd(), "data")
16
+ input_dir = os.path.join(os.getcwd(), "background_image")
17
+ if not os.path.exists(output_dir):
18
+ os.makedirs(output_dir)
19
+
20
+ data = []
21
+ append = (file != 1)
22
+
23
+ for n in num_objects_list:
24
+ for img_index in range(num_images):
25
+ im = Image.open(os.path.join(input_dir, f"bg_{img_index+1}.png"))
26
+ fig, ax = plt.subplots()
27
+ ax.imshow(im)
28
+ ax.set_aspect('equal')
29
+ plt.axis('off')
30
+
31
+ # Adjust plot limits to prevent cutoff
32
+ #plt.xlim(-1500.0, 1500.0)
33
+ #plt.ylim(-1000, 1000)
34
+
35
+ # Generate random positions for the shapes
36
+ positions = []
37
+ radius = 150
38
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
39
+ #colours = ['red', 'green', 'blue', 'yellow', 'orange', 'pink']
40
+ height, width = im.size
41
+ gold_answer = []
42
+ for i in range(n):
43
+ while True:
44
+ x, y = random.randint(2*radius, height-(2*radius)), random.randint(2*radius, width-(2*radius))
45
+ # Ensure shapes don't overlap
46
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
47
+ positions.append((x, y))
48
+ break
49
+
50
+ # Choose one odd-colored shape
51
+ #odd_index = random.randint(0, n - 1)
52
+
53
+ # Draw shapes and label them
54
+ colours = {'black', 'gray', 'brown', 'maroon', 'red', 'coral', 'tan', 'orange', 'ivory', 'goldenrod', 'yellow', 'green', 'olive', 'turquoise', 'skyblue', 'blue', 'lavender', 'purple', 'pink', 'fuchsia'}
55
+ colours_n = random.choice(list(combinations(colours, n)))
56
+ for i, (x, y) in enumerate(positions):
57
+ color = colours_n[i]
58
+ shape_type = random.choice(shapes)
59
+ gold_answer.append(color)
60
+
61
+ if shape_type == 'circle':
62
+ shape = plt.Circle((x, y), radius, color=color)
63
+ elif shape_type == 'triangle':
64
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
65
+ shape = plt.Polygon(triangle, color=color)
66
+ elif shape_type == 'rectangle':
67
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color)
68
+ elif shape_type == 'pentagon':
69
+ pentagon = np.array([
70
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
71
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
72
+ [x - 0.95 * radius, y + 0.31 * radius]
73
+ ])
74
+ shape = plt.Polygon(pentagon, color=color)
75
+
76
+ ax.add_patch(shape)
77
+ #ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
78
+
79
+ # Save the plot to a file
80
+ filename = f"{file}.png"
81
+ filepath = os.path.join(output_dir, filename)
82
+ plt.savefig(filepath, bbox_inches='tight')
83
+ plt.close()
84
+ answer = sorted(gold_answer)
85
+ img1 = cv2.imread("data/"+f"{file}.png")
86
+ img2 = cv2.imread("swatches.png")
87
+ if img1.shape[1] != img2.shape[1]:
88
+ max_width = max(img1.shape[1], img2.shape[1])
89
+ img1 = cv2.resize(img1, (max_width, img1.shape[0]))
90
+ img2 = cv2.resize(img2, (max_width, img2.shape[0]))
91
+
92
+ merged_image = cv2.vconcat([img1, img2])
93
+ cv2.imwrite(filepath, merged_image)
94
+ file += 1
95
+ gold_output = {
96
+ "id": filename,
97
+ "list_colours": answer,
98
+ "num_objects": n
99
+ }
100
+ data.append(gold_output)
101
+
102
+
103
+ if append:
104
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
105
+ old_data = json.load(f)
106
+ old_data.extend(data)
107
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
108
+ json.dump(old_data, f, indent=2)
109
+ else:
110
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
111
+ json.dump(data, f, indent=2)
112
+
113
+
114
+
115
+ # # Example usage
116
+ # generate_shapes(10, 'shapes.png')
117
+ if __name__ == "__main__":
118
+ # Parse command line arguments
119
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
120
+ parser.add_argument(
121
+ '--num_images',
122
+ type=int,
123
+ help='Number of images to generate',
124
+ default=1
125
+ )
126
+ parser.add_argument(
127
+ '--num_sizes',
128
+ nargs='*',
129
+ type=int,
130
+ help='List of count of objects',
131
+ default=[5]
132
+ )
133
+ parser.add_argument(
134
+ '--file',
135
+ type=int,
136
+ help='Starting file number',
137
+ default=1
138
+ )
139
+ args = parser.parse_args()
140
+ file = args.file
141
+ num_object_list = args.num_sizes
142
+ append = (file != 1)
143
+ generate_shapes(args.num_images, num_object_list , file)
list_colours/swatches.png ADDED

Git LFS Details

  • SHA256: 0e4f54072d7925f22d0ae80efa52d3eb47e1d929fe515d850bbbd6441d304936
  • Pointer size: 130 Bytes
  • Size of remote file: 21.4 kB
list_shapes/script.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import PIL
3
+ from PIL import Image
4
+ import random
5
+ import numpy as np
6
+ import os
7
+ import json
8
+ import argparse
9
+
10
+ def generate_shapes(num_images, num_objects_list , file):
11
+ # Set up the plot
12
+
13
+ output_dir = os.path.join(os.getcwd(), "data")
14
+ input_dir = os.path.join(os.getcwd(), "background_image")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ append = (file != 1)
20
+
21
+ for n in num_objects_list:
22
+ for img_index in range(num_images):
23
+ im = Image.open(os.path.join(input_dir, f"bg_{img_index+1}.png"))
24
+ fig, ax = plt.subplots()
25
+ ax.imshow(im)
26
+ ax.set_aspect('equal')
27
+ plt.axis('off')
28
+
29
+ # Adjust plot limits to prevent cutoff
30
+ #plt.xlim(-1500.0, 1500.0)
31
+ #plt.ylim(-1000, 1000)
32
+
33
+ # Generate random positions for the shapes
34
+ positions = []
35
+ radius = 75
36
+ shapes = ['circle', 'triangle', 'square', 'pentagon']
37
+ colours = ['red', 'green', 'blue']
38
+ height, width = im.size
39
+ gold_answer = set()
40
+ for i in range(n):
41
+ while True:
42
+ x, y = random.randint(2*radius, height-(2*radius)), random.randint(2*radius, width-(2*radius))
43
+ # Ensure shapes don't overlap
44
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
45
+ positions.append((x, y))
46
+ break
47
+
48
+ # Choose one odd-colored shape
49
+ #odd_index = random.randint(0, n - 1)
50
+
51
+ # Draw shapes and label them
52
+ for i, (x, y) in enumerate(positions):
53
+ color = random.choice(colours)
54
+ shape_type = random.choice(shapes)
55
+ gold_answer.add(shape_type)
56
+
57
+ if shape_type == 'circle':
58
+ shape = plt.Circle((x, y), radius, color=color)
59
+ elif shape_type == 'triangle':
60
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
61
+ shape = plt.Polygon(triangle, color=color)
62
+ elif shape_type == 'square':
63
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color)
64
+ elif shape_type == 'pentagon':
65
+ pentagon = np.array([
66
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
67
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
68
+ [x - 0.95 * radius, y + 0.31 * radius]
69
+ ])
70
+ shape = plt.Polygon(pentagon, color=color)
71
+
72
+ ax.add_patch(shape)
73
+ #ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
74
+
75
+ # Save the plot to a file
76
+ filename = f"{file}.png"
77
+ file += 1
78
+ filepath = os.path.join(output_dir, filename)
79
+ plt.savefig(filepath, bbox_inches='tight')
80
+ plt.close()
81
+ answer = sorted(list(gold_answer))
82
+
83
+ gold_output = {
84
+ "id": filename,
85
+ "list_shapes": answer,
86
+ "num_objects": n
87
+ }
88
+ data.append(gold_output)
89
+
90
+
91
+ if append:
92
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
93
+ old_data = json.load(f)
94
+ old_data.extend(data)
95
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
96
+ json.dump(old_data, f, indent=2)
97
+ else:
98
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
99
+ json.dump(data, f, indent=2)
100
+
101
+
102
+
103
+ # # Example usage
104
+ # generate_shapes(10, 'shapes.png')
105
+ if __name__ == "__main__":
106
+ # Parse command line arguments
107
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
108
+ parser.add_argument(
109
+ '--num_images',
110
+ type=int,
111
+ help='Number of images to generate',
112
+ default=1
113
+ )
114
+ parser.add_argument(
115
+ '--num_sizes',
116
+ nargs='*',
117
+ type=int,
118
+ help='List of count of objects',
119
+ default=[5]
120
+ )
121
+ parser.add_argument(
122
+ '--file',
123
+ type=int,
124
+ help='Starting file number',
125
+ default=1
126
+ )
127
+ args = parser.parse_args()
128
+ file = args.file
129
+ num_object_list = args.num_sizes
130
+ append = (file != 1)
131
+ generate_shapes(args.num_images, num_object_list , file)
locate_circles_colour/script.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+ import random
3
+ import argparse
4
+ import os
5
+ import json
6
+
7
+ def create_labeled_grid(n, m, cell_size=100, margin=40):
8
+ """
9
+ Create and save an image with a labeled grid.
10
+
11
+ Args:
12
+ rows (int): Number of rows in the grid
13
+ cols (int): Number of columns in the grid
14
+ cell_size (int): Size of each cell in pixels
15
+ margin (int): Margin around the grid for labels
16
+ filename (str): Name of the output file
17
+ """
18
+ global file, output_dir
19
+
20
+ rows = cols = n
21
+
22
+ # Calculate total size including margins for labels
23
+ width = cols * cell_size + 2 * margin
24
+ height = rows * cell_size + 2 * margin
25
+
26
+ # Create a new white image
27
+ image = Image.new('RGB', (width, height), 'white')
28
+ draw = ImageDraw.Draw(image)
29
+
30
+ # Try to use Arial font, fall back to default if not available
31
+ try:
32
+ font = ImageFont.truetype("arial.ttf", size=20)
33
+ except IOError:
34
+ font = ImageFont.load_default()
35
+
36
+ # Draw vertical lines and column labels
37
+ for i in range(cols + 1):
38
+ x = margin + i * cell_size
39
+ # Draw vertical line
40
+ draw.line([(x, margin), (x, height - margin)], fill='black', width=2)
41
+ # Draw column label (skip last number)
42
+ if i < cols:
43
+ label = str(i + 1)
44
+ # Get text size for centering
45
+ text_bbox = draw.textbbox((0, 0), label, font=font)
46
+ text_width = text_bbox[2] - text_bbox[0]
47
+ draw.text((x + (cell_size - text_width) // 2, margin // 2),
48
+ label, fill='black', font=font)
49
+
50
+ # Draw horizontal lines and row labels
51
+ for i in range(rows + 1):
52
+ y = margin + i * cell_size
53
+ # Draw horizontal line
54
+ draw.line([(margin, y), (width - margin, y)], fill='black', width=2)
55
+ # Draw row label (skip last number)
56
+ if i < rows:
57
+ # Changed from letters to numbers
58
+ label = str(i + 1)
59
+ text_bbox = draw.textbbox((0, 0), label, font=font)
60
+ text_height = text_bbox[3] - text_bbox[1]
61
+ draw.text((margin // 2, y + (cell_size - text_height) // 2),
62
+ label, fill='black', font=font)
63
+
64
+ shape_colors = ['red', 'blue', 'purple' , 'yellow']
65
+ shape_types = ['circle']
66
+
67
+ coord_list = []
68
+
69
+ # for random m cells draw a green circle in them
70
+ k = 0
71
+
72
+ while k < m:
73
+ i = random.randint(0, rows - 1)
74
+ j = random.randint(0, cols - 1)
75
+ if (i+1, j+1) in coord_list:
76
+ # k -= 1
77
+ continue
78
+ # print(k , i, j)
79
+ top_left = (margin + j * cell_size + 5, margin + i * cell_size + 5)
80
+ bottom_right = (margin + (j + 1) * cell_size - 5, margin + (i + 1) * cell_size - 5)
81
+ draw.ellipse([top_left, bottom_right], fill='green')
82
+ coord_list.append((i+1, j+1))
83
+ k += 1
84
+
85
+ for i in range(rows):
86
+ for j in range(cols):
87
+ if (i+1, j+1) not in coord_list:
88
+ shape_type = random.choice(shape_types)
89
+ if shape_type != 'circle':
90
+ shape_color = random.choice(shape_colors + ['green'])
91
+ else:
92
+ shape_color = random.choice(shape_colors)
93
+ top_left = (margin + j * cell_size + 5, margin + i * cell_size + 5)
94
+ bottom_right = (margin + (j + 1) * cell_size - 5, margin + (i + 1) * cell_size - 5)
95
+ if shape_type == 'circle':
96
+ draw.ellipse([top_left, bottom_right], fill=shape_color)
97
+ elif shape_type == 'square':
98
+ draw.rectangle([top_left, bottom_right], fill=shape_color)
99
+ elif shape_type == 'triangle':
100
+ mid_x = (top_left[0] + bottom_right[0]) / 2
101
+ draw.polygon([top_left, (bottom_right[0], top_left[1]), (mid_x, bottom_right[1])], fill=shape_color)
102
+
103
+
104
+ image_filename = f"{file}.png"
105
+ file += 1
106
+ image_path = os.path.join(output_dir, image_filename)
107
+ image.save(image_path)
108
+
109
+ return coord_list
110
+
111
+ # Example usage
112
+ if __name__ == "__main__":
113
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
114
+ parser.add_argument(
115
+ '--num_images',
116
+ type=int,
117
+ help='Number of images to generate',
118
+ default=1
119
+ )
120
+ parser.add_argument(
121
+ '--num_sizes',
122
+ nargs='*',
123
+ help='List of n values',
124
+ default=[5 , 3]
125
+ )
126
+ parser.add_argument(
127
+ '--grid_size',
128
+ type=int,
129
+ help='Grid size',
130
+ default=6
131
+ )
132
+ parser.add_argument(
133
+ '--file',
134
+ type=int,
135
+ help='Starting file number',
136
+ default=1
137
+ )
138
+ args = parser.parse_args()
139
+ file = args.file
140
+ num_sizes = args.num_sizes
141
+ append = (file != 1)
142
+ data = []
143
+ output_dir = os.path.join(os.getcwd(), "data")
144
+ if not os.path.exists(output_dir):
145
+ os.makedirs(output_dir)
146
+
147
+ for j in range(0, len(num_sizes)):
148
+ for i in range(args.num_images):
149
+ rows = args.grid_size
150
+ n_circles = int(num_sizes[j])
151
+ coord_list = create_labeled_grid(rows, n_circles)
152
+ # print(grid)
153
+ data.append({
154
+ 'id': f"{file-1}.png",
155
+ 'rows': rows,
156
+ 'n_circles': n_circles,
157
+ 'gold_output': coord_list
158
+ })
159
+
160
+ if append:
161
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
162
+ old_data = json.load(f)
163
+ old_data.extend(data)
164
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
165
+ json.dump(old_data, f, indent=2)
166
+ else:
167
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
168
+ json.dump(data, f, indent=2)
locate_circles_shape/script.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+ import random
3
+ import argparse
4
+ import os
5
+ import json
6
+
7
+ def create_labeled_grid(n, m, cell_size=100, margin=40):
8
+ """
9
+ Create and save an image with a labeled grid.
10
+
11
+ Args:
12
+ rows (int): Number of rows in the grid
13
+ cols (int): Number of columns in the grid
14
+ cell_size (int): Size of each cell in pixels
15
+ margin (int): Margin around the grid for labels
16
+ filename (str): Name of the output file
17
+ """
18
+ global file, output_dir
19
+
20
+ rows = cols = n
21
+
22
+ # Calculate total size including margins for labels
23
+ width = cols * cell_size + 2 * margin
24
+ height = rows * cell_size + 2 * margin
25
+
26
+ # Create a new white image
27
+ image = Image.new('RGB', (width, height), 'white')
28
+ draw = ImageDraw.Draw(image)
29
+
30
+ # Try to use Arial font, fall back to default if not available
31
+ try:
32
+ font = ImageFont.truetype("arial.ttf", size=20)
33
+ except IOError:
34
+ font = ImageFont.load_default()
35
+
36
+ # Draw vertical lines and column labels
37
+ for i in range(cols + 1):
38
+ x = margin + i * cell_size
39
+ # Draw vertical line
40
+ draw.line([(x, margin), (x, height - margin)], fill='black', width=2)
41
+ # Draw column label (skip last number)
42
+ if i < cols:
43
+ label = str(i + 1)
44
+ # Get text size for centering
45
+ text_bbox = draw.textbbox((0, 0), label, font=font)
46
+ text_width = text_bbox[2] - text_bbox[0]
47
+ draw.text((x + (cell_size - text_width) // 2, margin // 2),
48
+ label, fill='black', font=font)
49
+
50
+ # Draw horizontal lines and row labels
51
+ for i in range(rows + 1):
52
+ y = margin + i * cell_size
53
+ # Draw horizontal line
54
+ draw.line([(margin, y), (width - margin, y)], fill='black', width=2)
55
+ # Draw row label (skip last number)
56
+ if i < rows:
57
+ # Changed from letters to numbers
58
+ label = str(i + 1)
59
+ text_bbox = draw.textbbox((0, 0), label, font=font)
60
+ text_height = text_bbox[3] - text_bbox[1]
61
+ draw.text((margin // 2, y + (cell_size - text_height) // 2),
62
+ label, fill='black', font=font)
63
+
64
+ shape_colors = ['green']
65
+ shape_types = ['square', 'triangle']
66
+
67
+ coord_list = []
68
+
69
+ # for random m cells draw a green circle in them
70
+ k = 0
71
+
72
+ while k < m:
73
+ i = random.randint(0, rows - 1)
74
+ j = random.randint(0, cols - 1)
75
+ if (i+1, j+1) in coord_list:
76
+ # k -= 1
77
+ continue
78
+ # print(k , i, j)
79
+ top_left = (margin + j * cell_size + 5, margin + i * cell_size + 5)
80
+ bottom_right = (margin + (j + 1) * cell_size - 5, margin + (i + 1) * cell_size - 5)
81
+ draw.ellipse([top_left, bottom_right], fill='green')
82
+ coord_list.append((i+1, j+1))
83
+ k += 1
84
+
85
+ for i in range(rows):
86
+ for j in range(cols):
87
+ if (i+1, j+1) not in coord_list:
88
+ shape_type = random.choice(shape_types)
89
+ if shape_type != 'circle':
90
+ shape_color = random.choice(shape_colors + ['green'])
91
+ else:
92
+ shape_color = random.choice(shape_colors)
93
+ top_left = (margin + j * cell_size + 5, margin + i * cell_size + 5)
94
+ bottom_right = (margin + (j + 1) * cell_size - 5, margin + (i + 1) * cell_size - 5)
95
+ if shape_type == 'circle':
96
+ draw.ellipse([top_left, bottom_right], fill=shape_color)
97
+ elif shape_type == 'square':
98
+ draw.rectangle([top_left, bottom_right], fill=shape_color)
99
+ elif shape_type == 'triangle':
100
+ mid_x = (top_left[0] + bottom_right[0]) / 2
101
+ draw.polygon([top_left, (bottom_right[0], top_left[1]), (mid_x, bottom_right[1])], fill=shape_color)
102
+
103
+
104
+ image_filename = f"{file}.png"
105
+ file += 1
106
+ image_path = os.path.join(output_dir, image_filename)
107
+ image.save(image_path)
108
+
109
+ return coord_list
110
+
111
+ # Example usage
112
+ if __name__ == "__main__":
113
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
114
+ parser.add_argument(
115
+ '--num_images',
116
+ type=int,
117
+ help='Number of images to generate',
118
+ default=1
119
+ )
120
+ parser.add_argument(
121
+ '--num_sizes',
122
+ nargs='*',
123
+ help='List of n values',
124
+ default=[5 , 3]
125
+ )
126
+ parser.add_argument(
127
+ '--grid_size',
128
+ type=int,
129
+ help='Grid size',
130
+ default=6
131
+ )
132
+ parser.add_argument(
133
+ '--file',
134
+ type=int,
135
+ help='Starting file number',
136
+ default=1
137
+ )
138
+ args = parser.parse_args()
139
+ file = args.file
140
+ num_sizes = args.num_sizes
141
+ append = (file != 1)
142
+ data = []
143
+ output_dir = os.path.join(os.getcwd(), "data")
144
+ if not os.path.exists(output_dir):
145
+ os.makedirs(output_dir)
146
+
147
+ for j in range(0, len(num_sizes)):
148
+ for i in range(args.num_images):
149
+ rows = args.grid_size
150
+ n_circles = int(num_sizes[j])
151
+ coord_list = create_labeled_grid(rows, n_circles)
152
+ # print(grid)
153
+ data.append({
154
+ 'id': f"{file-1}.png",
155
+ 'rows': rows,
156
+ 'n_circles': n_circles,
157
+ 'gold_output': coord_list
158
+ })
159
+
160
+ if append:
161
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
162
+ old_data = json.load(f)
163
+ old_data.extend(data)
164
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
165
+ json.dump(old_data, f, indent=2)
166
+ else:
167
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
168
+ json.dump(data, f, indent=2)
match_outline/script.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+ import random
4
+ import os
5
+ import json
6
+ import argparse
7
+
8
+ def create_images(num_images, num_objects_list , file):
9
+ # Ensure the output directory exists
10
+ output_dir = os.path.join(os.getcwd(), "data")
11
+ if not os.path.exists(output_dir):
12
+ os.makedirs(output_dir)
13
+
14
+ data = []
15
+
16
+ append = (file != 1)
17
+ for num_objects in num_objects_list:
18
+ dpi = 100 # Dots per inch
19
+ width_inches = 1 # 100 pixels
20
+ height_inches = num_objects + 1 # 100 pixels per row
21
+ for img_index in range(num_images):
22
+ shapes1, shapes2 = [], []
23
+ fig, ax = plt.subplots(figsize=(width_inches, height_inches), dpi=dpi)
24
+ for i in range (num_objects):
25
+ y = num_objects - i - 1
26
+ x = 0.5
27
+ radius = 0.1
28
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
29
+ #colours = ['red', 'green', 'blue']
30
+
31
+
32
+ # Add circles to the plot
33
+ shape_type = random.choice(shapes)
34
+ shapes1.append(shape_type)
35
+ if shape_type == 'circle':
36
+ shape = plt.Circle((x, y), radius, color="blue")
37
+ elif shape_type == 'triangle':
38
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
39
+ shape = plt.Polygon(triangle, color="blue")
40
+ elif shape_type == 'rectangle':
41
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color="blue")
42
+ elif shape_type == 'pentagon':
43
+ pentagon = np.array([
44
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
45
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
46
+ [x - 0.95 * radius, y + 0.31 * radius]
47
+ ])
48
+ shape = plt.Polygon(pentagon, color="blue")
49
+ ax.add_patch(shape)
50
+
51
+ # if i < num_objects -1:
52
+ ax.plot([0, 1], [y - 0.5, y - 0.5], color='black')
53
+
54
+ ax.set_xlim(0, 1)
55
+ ax.set_ylim(-0.6, num_objects - 0.5)
56
+ ax.set_aspect('equal')
57
+ ax.axis('off')
58
+
59
+ image_filename = f"first{file}.png"
60
+ image_path = os.path.join(output_dir, image_filename)
61
+ plt.savefig(image_path, bbox_inches='tight', dpi=dpi)
62
+ plt.close(fig)
63
+
64
+ fig, ax = plt.subplots(figsize=(width_inches, height_inches), dpi=dpi)
65
+ for i in range (num_objects):
66
+ y = num_objects - i - 1
67
+ x = 0.5
68
+ radius = 0.1
69
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
70
+ #colours = ['red', 'green', 'blue']
71
+
72
+
73
+ # Add circles to the plot
74
+ shape_type = random.choice(shapes)
75
+ shapes2.append(shape_type)
76
+ if shape_type == 'circle':
77
+ shape = plt.Circle((x, y), radius, ec="blue", fill=False)
78
+ elif shape_type == 'triangle':
79
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
80
+ shape = plt.Polygon(triangle, ec="blue", fill = False)
81
+ elif shape_type == 'rectangle':
82
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, ec="blue", fill=False)
83
+ elif shape_type == 'pentagon':
84
+ pentagon = np.array([
85
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
86
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
87
+ [x - 0.95 * radius, y + 0.31 * radius]
88
+ ])
89
+ shape = plt.Polygon(pentagon, ec="blue", fill=False)
90
+ ax.add_patch(shape)
91
+
92
+ # if i < num_objects -1:
93
+ ax.plot([0, 1], [y - 0.5, y - 0.5], color='black')
94
+
95
+ ax.set_xlim(0, 1)
96
+ ax.set_ylim(-0.6, num_objects - 0.5)
97
+ ax.set_aspect('equal')
98
+ ax.axis('off')
99
+
100
+ image_filename = f"second{file}.png"
101
+ file += 1
102
+ image_path = os.path.join(output_dir, image_filename)
103
+ plt.savefig(image_path, bbox_inches='tight', dpi=dpi)
104
+ plt.close(fig)
105
+
106
+ answer = 0
107
+ for i in range(num_objects):
108
+ if(shapes1[i] == shapes2[i]):
109
+ answer += 1
110
+
111
+
112
+
113
+ # Store the number of objects in the image_data dictionary
114
+ gold_output = {
115
+ "id": image_filename,
116
+ "Gold_output": answer,
117
+ "Rows" : num_objects
118
+ }
119
+ data.append(gold_output)
120
+
121
+ if append:
122
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
123
+ old_data = json.load(f)
124
+ old_data.extend(data)
125
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
126
+ json.dump(old_data, f, indent=2)
127
+ else:
128
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
129
+ json.dump(data, f, indent=2)
130
+
131
+ if __name__ == "__main__":
132
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
133
+ parser.add_argument(
134
+ '--num_images',
135
+ type=int,
136
+ help='Number of images to generate',
137
+ default=1
138
+ )
139
+ parser.add_argument(
140
+ '--num_sizes',
141
+ nargs='*',
142
+ type=int,
143
+ help='List of number of rows',
144
+ default=[5]
145
+ )
146
+ parser.add_argument(
147
+ '--file',
148
+ type=int,
149
+ help='Starting file number',
150
+ default=1
151
+ )
152
+ args = parser.parse_args()
153
+ file = args.file
154
+ num_object_list = args.num_sizes
155
+ append = (file != 1)
156
+ create_images(args.num_images, num_object_list , file)
match_shadow/script.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+ import random
4
+ import os
5
+ import json
6
+ import argparse
7
+
8
+ def create_images(num_images, num_objects_list , file):
9
+ # Ensure the output directory exists
10
+ output_dir = os.path.join(os.getcwd(), "data")
11
+ if not os.path.exists(output_dir):
12
+ os.makedirs(output_dir)
13
+
14
+ data = []
15
+
16
+ append = (file != 1)
17
+ for num_objects in num_objects_list:
18
+ dpi = 100 # Dots per inch
19
+ width_inches = 1 # 100 pixels
20
+ height_inches = num_objects + 1 # 100 pixels per row
21
+ for img_index in range(num_images):
22
+ shapes1, shapes2 = [], []
23
+ fig, ax = plt.subplots(figsize=(width_inches, height_inches), dpi=dpi)
24
+ for i in range (num_objects):
25
+ y = num_objects - i - 1
26
+ x = 0.5
27
+ radius = 0.1
28
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
29
+ #colours = ['red', 'green', 'blue']
30
+
31
+
32
+ # Add circles to the plot
33
+ shape_type = random.choice(shapes)
34
+ shapes1.append(shape_type)
35
+ if shape_type == 'circle':
36
+ shape = plt.Circle((x, y), radius, color="blue")
37
+ elif shape_type == 'triangle':
38
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
39
+ shape = plt.Polygon(triangle, color="blue")
40
+ elif shape_type == 'rectangle':
41
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color="blue")
42
+ elif shape_type == 'pentagon':
43
+ pentagon = np.array([
44
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
45
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
46
+ [x - 0.95 * radius, y + 0.31 * radius]
47
+ ])
48
+ shape = plt.Polygon(pentagon, color="blue")
49
+ ax.add_patch(shape)
50
+
51
+ # if i < num_objects -1:
52
+ ax.plot([0, 1], [y - 0.5, y - 0.5], color='black')
53
+
54
+ ax.set_xlim(0, 1)
55
+ ax.set_ylim(-0.6, num_objects - 0.5)
56
+ ax.set_aspect('equal')
57
+ ax.axis('off')
58
+
59
+ image_filename = f"first{file}.png"
60
+ image_path = os.path.join(output_dir, image_filename)
61
+ plt.savefig(image_path, bbox_inches='tight', dpi=dpi)
62
+ plt.close(fig)
63
+
64
+ fig, ax = plt.subplots(figsize=(width_inches, height_inches), dpi=dpi)
65
+ for i in range (num_objects):
66
+ y = num_objects - i - 1
67
+ x = 0.5
68
+ radius = 0.1
69
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
70
+ #colours = ['red', 'green', 'blue']
71
+
72
+
73
+ # Add circles to the plot
74
+ shape_type = random.choice(shapes)
75
+ shapes2.append(shape_type)
76
+ if shape_type == 'circle':
77
+ shape = plt.Circle((x, y), radius, color="blue")
78
+ elif shape_type == 'triangle':
79
+ triangle = np.array([[x, y - radius], [x - radius, y + radius], [x + radius, y + radius]])
80
+ shape = plt.Polygon(triangle, color="blue")
81
+ elif shape_type == 'rectangle':
82
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color="blue")
83
+ elif shape_type == 'pentagon':
84
+ pentagon = np.array([
85
+ [x, y - radius], [x + 0.95 * radius, y - 0.31 * radius],
86
+ [x + 0.59 * radius, y + 0.81 * radius], [x - 0.59 * radius, y + 0.81 * radius],
87
+ [x - 0.95 * radius, y - 0.31 * radius]
88
+ ])
89
+ shape = plt.Polygon(pentagon, color="blue")
90
+ ax.add_patch(shape)
91
+
92
+ # if i < num_objects -1:
93
+ ax.plot([0, 1], [y - 0.5, y - 0.5], color='black')
94
+
95
+ ax.set_xlim(0, 1)
96
+ ax.set_ylim(-0.6, num_objects - 0.5)
97
+ ax.set_aspect('equal')
98
+ ax.axis('off')
99
+
100
+ image_filename = f"second{file}.png"
101
+ file += 1
102
+ image_path = os.path.join(output_dir, image_filename)
103
+ plt.savefig(image_path, bbox_inches='tight', dpi=dpi)
104
+ plt.close(fig)
105
+
106
+ answer = 0
107
+ for i in range(num_objects):
108
+ if(shapes1[i] == shapes2[i]):
109
+ answer += 1
110
+
111
+
112
+
113
+ # Store the number of objects in the image_data dictionary
114
+ gold_output = {
115
+ "id": image_filename,
116
+ "Gold_output": answer,
117
+ "Rows" : num_objects
118
+ }
119
+ data.append(gold_output)
120
+
121
+ if append:
122
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
123
+ old_data = json.load(f)
124
+ old_data.extend(data)
125
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
126
+ json.dump(old_data, f, indent=2)
127
+ else:
128
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
129
+ json.dump(data, f, indent=2)
130
+
131
+ if __name__ == "__main__":
132
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
133
+ parser.add_argument(
134
+ '--num_images',
135
+ type=int,
136
+ help='Number of images to generate',
137
+ default=1
138
+ )
139
+ parser.add_argument(
140
+ '--num_sizes',
141
+ nargs='*',
142
+ type=int,
143
+ help='List of number of rows',
144
+ default=[5]
145
+ )
146
+ parser.add_argument(
147
+ '--file',
148
+ type=int,
149
+ help='Starting file number',
150
+ default=1
151
+ )
152
+ args = parser.parse_args()
153
+ file = args.file
154
+ num_object_list = args.num_sizes
155
+ append = (file != 1)
156
+ create_images(args.num_images, num_object_list , file)
maze_solving/script.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+ import random
3
+ import os
4
+ import argparse
5
+ import json
6
+ # Global counter to ensure unique numbering across the entire maze
7
+ current_path_number = 1
8
+ end_x, end_y = 1, 1
9
+ path_length = 3
10
+
11
+ def create_grid(n, m):
12
+ grid = [['#' for _ in range(m)] for _ in range(n)]
13
+ return grid
14
+
15
+ def carve_path(grid, x, y):
16
+ global current_path_number
17
+ global end_x, end_y
18
+ global path_length
19
+ grid[x][y] = str(current_path_number)
20
+ current_path_number += 1
21
+ directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
22
+ random.shuffle(directions)
23
+
24
+ for dx, dy in directions:
25
+ nx, ny = x + dx * 2, y + dy * 2
26
+ if 0 <= nx < len(grid) and 0 <= ny < len(grid[0]) and grid[nx][ny] == '#':
27
+ grid[x + dx][y + dy] = str(current_path_number)
28
+ if current_path_number == path_length:
29
+ end_x, end_y = x+dx, y+dy
30
+ current_path_number += 1
31
+ carve_path(grid, nx, ny)
32
+
33
+ def find_solution(grid, start_pos, end_pos):
34
+ # BFS to find the optimal path
35
+ from collections import deque
36
+
37
+ n, m = len(grid), len(grid[0])
38
+ directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
39
+ queue = deque([(start_pos, [grid[start_pos[0]][start_pos[1]]])])
40
+ visited = set([start_pos])
41
+
42
+ while queue:
43
+ (x, y), path = queue.popleft()
44
+
45
+ if (x, y) == end_pos:
46
+ return path
47
+
48
+ for dx, dy in directions:
49
+ nx, ny = x + dx, y + dy
50
+ if 0 <= nx < n and 0 <= ny < m and (nx, ny) not in visited and grid[nx][ny] != '#':
51
+ queue.append(((nx, ny), path + [grid[nx][ny]]))
52
+ visited.add((nx, ny))
53
+
54
+ return []
55
+
56
+ def generate_maze(n, m, path):
57
+ global current_path_number
58
+ global path_length
59
+ current_path_number = 1 # Reset global counter for new maze
60
+ path_length = path
61
+
62
+ grid = create_grid(n, m)
63
+ start_x, start_y = random.choice(range(1, n, 2)), random.choice(range(1, m, 2))
64
+ carve_path(grid, start_x, start_y)
65
+
66
+ # Set the end position at the farthest point from the start
67
+ #end_x, end_y = random.choice(range(1, n, 2)), random.choice(range(1, m, 2))
68
+
69
+ # Ensure start and end are not the same
70
+ """while (end_x, end_y) == (start_x, start_y):
71
+ end_x, end_y = random.choice(range(1, n, 2)), random.choice(range(1, m, 2))"""
72
+
73
+ global end_x, end_y
74
+ if end_x == 1 and end_y == 1:
75
+ for x in range(n):
76
+ for y in range(m):
77
+ if grid[x][y] == str(path_length):
78
+ end_x, end_y = x, y
79
+ break
80
+ grid[start_x][start_y] = "S" # Label the start
81
+ grid[end_x][end_y] = "E" # Label the end
82
+
83
+ solution = find_solution(grid, (start_x, start_y), (end_x, end_y))
84
+ end_x, end_y = 1, 1
85
+ return grid, (start_x, start_y), (end_x, end_y), solution
86
+
87
+ def maze_to_image(grid, cell_size=40):
88
+ n, m = len(grid), len(grid[0])
89
+ img = Image.new("RGB", (m * cell_size, n * cell_size), color="white")
90
+ draw = ImageDraw.Draw(img)
91
+
92
+ for i, row in enumerate(grid):
93
+ for j, cell in enumerate(row):
94
+ top_left = (j * cell_size, i * cell_size)
95
+ bottom_right = ((j + 1) * cell_size, (i + 1) * cell_size)
96
+ draw.rectangle([top_left, bottom_right], outline="black", width=1) # Draw cell borders
97
+ if cell == '#':
98
+ draw.rectangle([top_left, bottom_right], fill="black")
99
+ elif cell == 'S': # Start cell
100
+ draw.rectangle([top_left, bottom_right], fill="white" , outline="black", width=1)
101
+ draw.text((top_left[0] + cell_size//4, top_left[1] + cell_size//4), "S", fill="black")
102
+
103
+ elif cell == 'E': # End cell
104
+ draw.rectangle([top_left, bottom_right], fill="white" , outline="black", width=1)
105
+ draw.text((top_left[0] + cell_size//4, top_left[1] + cell_size//4), "E", fill="black")
106
+ else:
107
+ draw.rectangle([top_left, bottom_right], fill="white" , outline="black", width=1)
108
+ draw.text((top_left[0] + cell_size//4, top_left[1] + cell_size//4), cell, fill="blue")
109
+
110
+ return img
111
+
112
+ if __name__ == "__main__":
113
+ output_dir = os.path.join(os.getcwd(), "data")
114
+ if not os.path.exists(output_dir):
115
+ os.makedirs(output_dir)
116
+
117
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
118
+ parser.add_argument(
119
+ '--num_images',
120
+ type=int,
121
+ help='Number of images to generate',
122
+ default=1
123
+ )
124
+ parser.add_argument(
125
+ '--num_sizes',
126
+ nargs='*',
127
+ type=int,
128
+ help='List of n values (num rows , num columns) to generate',
129
+ default=[5 , 5]
130
+ )
131
+ parser.add_argument(
132
+ '--file',
133
+ type=int,
134
+ help='Starting file number',
135
+ default=1
136
+ )
137
+ args = parser.parse_args()
138
+
139
+ file = args.file
140
+ data = []
141
+ append = (file != 1)
142
+ num_images = args.num_images
143
+ num_size = args.num_sizes
144
+ # num_images = int(sys.argv[1])
145
+ # num_size = sys.argv[2:]
146
+ # num_size = [int(num_objects) for num_objects in num_size]
147
+ # n, m = 11, 11 # Dimensions of the maze (should be odd numbers)
148
+ for i in range(0 , len(num_size)):
149
+ n = 11
150
+ m = 11
151
+ for _ in range(num_images):
152
+ maze, start_pos, end_pos, solution = generate_maze(n, m, num_size[i])
153
+ # solution = [int(cell) for cell in solution]
154
+ img = maze_to_image(maze)
155
+ # img.show()
156
+ gold_output = {
157
+ "id": f"{file}.png",
158
+ "path": solution,
159
+ "Rows": n,
160
+ "Columns": m
161
+ }
162
+ file += 1
163
+ data.append(gold_output)
164
+ img.save(os.path.join(output_dir, gold_output["id"]))
165
+
166
+ if append:
167
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
168
+ old_data = json.load(f)
169
+ old_data.extend(data)
170
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
171
+ json.dump(old_data, f, indent=2)
172
+ else:
173
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
174
+ json.dump(data, f, indent=2)
175
+ # maze, start_pos, end_pos, solution = generate_maze(n, m)
176
+ # print("Optimal Solution Path (cell numbers):", solution)
177
+ # img = maze_to_image(maze)
178
+ # img.show()
179
+
mirror_image/script.py ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import cv2
3
+ import PIL
4
+ from PIL import Image
5
+ import random
6
+ import numpy as np
7
+ import os
8
+ import json
9
+ import argparse
10
+
11
+ def generate_shapes(num_images, num_objects_list , file):
12
+ # Set up the plot
13
+
14
+ output_dir = os.path.join(os.getcwd(), "data")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ append = (file != 1)
20
+
21
+ for n in num_objects_list:
22
+ max_obj = 2*n
23
+ for img_index in range(num_images):
24
+ """fig, ax = plt.subplots()
25
+ ax.set_aspect('equal')
26
+ plt.axis('off')
27
+
28
+ # Adjust plot limits to prevent cutoff
29
+ plt.xlim(-0.1, 1.1)
30
+ plt.ylim(-0.1, 1.1)
31
+
32
+ # Generate random positions for the shapes
33
+ positions = []
34
+ radius = 0.05
35
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
36
+ colours = ['red', 'green', 'blue', 'yellow', 'orange', 'black']
37
+ for i in range(n):
38
+ while True:
39
+ x, y = random.uniform(0.1, 0.9), random.uniform(0.1, 0.9)
40
+ # Ensure shapes don't overlap
41
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
42
+ positions.append((x, y))
43
+ break
44
+
45
+ # Choose one odd-colored shape
46
+ #odd_index = random.randint(0, n - 1)
47
+
48
+ # Draw shapes and label them
49
+ for i, (x, y) in enumerate(positions):
50
+ color = random.choice(colours)
51
+ shape_type = random.choice(shapes)
52
+
53
+ if shape_type == 'circle':
54
+ shape = plt.Circle((x, y), radius, color=color)
55
+ elif shape_type == 'triangle':
56
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
57
+ shape = plt.Polygon(triangle, color=color)
58
+ elif shape_type == 'rectangle':
59
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color)
60
+ elif shape_type == 'pentagon':
61
+ pentagon = np.array([
62
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
63
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
64
+ [x - 0.95 * radius, y + 0.31 * radius]
65
+ ])
66
+ shape = plt.Polygon(pentagon, color=color)
67
+
68
+ ax.add_patch(shape)"""
69
+ #ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
70
+
71
+ # Save the plot to a file
72
+ fig, ax = plt.subplots()
73
+ ax.set_aspect('equal')
74
+ plt.axis('off')
75
+
76
+ # Adjust plot limits to prevent cutoff
77
+ plt.xlim(-203.5, 203.5)
78
+ plt.ylim(-203.5, 203.5)
79
+
80
+ # Generate random positions for the shapes
81
+ positions = []
82
+ radius = 3.5
83
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
84
+ colours = ['red', 'green', 'blue', 'yellow', 'orange', 'black']
85
+ for i in range(max_obj):
86
+ while True:
87
+ x, y = random.uniform(-200, -3.5), random.uniform(-200, 200)
88
+ # Ensure shapes don't overlap
89
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
90
+ positions.append((x, y))
91
+ break
92
+
93
+ # Choose one odd-colored shape
94
+ #odd_index = random.randint(0, n - 1)
95
+
96
+ # Draw shapes and label them
97
+ color, shape_type = [], []
98
+ plt.axvline(x = 0, color = 'blue')
99
+ for i, (x, y) in enumerate(positions):
100
+ color.append(random.choice(colours))
101
+ shape_type.append(random.choice(shapes))
102
+
103
+ if shape_type[-1] == 'circle':
104
+ shape = plt.Circle((x, y), radius, color=color[-1])
105
+ elif shape_type[-1] == 'triangle':
106
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
107
+ shape = plt.Polygon(triangle, color=color[-1])
108
+ elif shape_type[-1] == 'rectangle':
109
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color[-1])
110
+ elif shape_type[-1] == 'pentagon':
111
+ pentagon = np.array([
112
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
113
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
114
+ [x - 0.95 * radius, y + 0.31 * radius]
115
+ ])
116
+ shape = plt.Polygon(pentagon, color=color[-1])
117
+
118
+ ax.add_patch(shape)
119
+ filename = f"first{file}.png"
120
+ filepath = os.path.join(output_dir, filename)
121
+ plt.savefig(filepath, bbox_inches='tight')
122
+ plt.close()
123
+
124
+ fig, ax = plt.subplots()
125
+ ax.set_aspect('equal')
126
+ plt.axis('off')
127
+
128
+ # Adjust plot limits to prevent cutoff
129
+ plt.xlim(-203.5, 203.5)
130
+ plt.ylim(-203.5, 203.5)
131
+
132
+ for i in range(n):
133
+ x = list(positions[i])
134
+ x[0] = -x[0]
135
+ positions[i] = tuple(x)
136
+
137
+ plt.axvline(x = 0, color = 'blue')
138
+ for i, (x, y) in enumerate(positions):
139
+ if shape_type[i] == 'circle':
140
+ shape = plt.Circle((x, y), radius, color=color[i])
141
+ elif shape_type[i] == 'triangle':
142
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
143
+ shape = plt.Polygon(triangle, color=color[i])
144
+ elif shape_type[i] == 'rectangle':
145
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color[i])
146
+ elif shape_type[i] == 'pentagon':
147
+ pentagon = np.array([
148
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
149
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
150
+ [x - 0.95 * radius, y + 0.31 * radius]
151
+ ])
152
+ shape = plt.Polygon(pentagon, color=color[i])
153
+
154
+ ax.add_patch(shape)
155
+ filename = f"second{file}.png"
156
+ file += 1
157
+ filepath = os.path.join(output_dir, filename)
158
+ plt.savefig(filepath, bbox_inches='tight')
159
+ plt.close()
160
+
161
+ gold_answer = n
162
+ """if choice == 0:
163
+ img = cv2.imread(filepath)
164
+ img_mirror = np.flip(img, axis=1)
165
+ cv2.imwrite(os.path.join(output_dir, f"second{file-1}.png"), img_mirror)
166
+ gold_answer = "Yes"
167
+ else:
168
+ angles = [90, 180, 270, 360]
169
+ angle = random.choice(angles)
170
+ img = Image.open(filepath)
171
+ rotated_image = img.rotate(angle, PIL.Image.BILINEAR)
172
+ rotated_image.save(os.path.join(output_dir, f"second{file-1}.png"), "PNG")
173
+ gold_answer = "No"
174
+
175
+ """
176
+
177
+
178
+ gold_output = {
179
+ "id": filename,
180
+ "mirror_image": gold_answer,
181
+ "num_objects": n
182
+ }
183
+ data.append(gold_output)
184
+
185
+
186
+ if append:
187
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
188
+ old_data = json.load(f)
189
+ old_data.extend(data)
190
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
191
+ json.dump(old_data, f, indent=2)
192
+ else:
193
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
194
+ json.dump(data, f, indent=2)
195
+
196
+
197
+
198
+ # # Example usage
199
+ # generate_shapes(10, 'shapes.png')
200
+ if __name__ == "__main__":
201
+ # Parse command line arguments
202
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
203
+ parser.add_argument(
204
+ '--num_images',
205
+ type=int,
206
+ help='Number of images to generate',
207
+ default=1
208
+ )
209
+ parser.add_argument(
210
+ '--num_sizes',
211
+ nargs='*',
212
+ type=int,
213
+ help='List of count of objects',
214
+ default=[5]
215
+ )
216
+ parser.add_argument(
217
+ '--file',
218
+ type=int,
219
+ help='Starting file number',
220
+ default=1
221
+ )
222
+ args = parser.parse_args()
223
+ file = args.file
224
+ num_object_list = args.num_sizes
225
+ append = (file != 1)
226
+ generate_shapes(args.num_images, num_object_list , file)
numbered_shapes/script.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import PIL
3
+ from PIL import Image
4
+ import random
5
+ import numpy as np
6
+ import os
7
+ import json
8
+ import argparse
9
+
10
+ def generate_shapes(num_images, num_objects_list , file):
11
+ # Set up the plot
12
+
13
+ output_dir = os.path.join(os.getcwd(), "data")
14
+ #input_dir = os.path.join(os.getcwd(), "background_image")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ #max_obj = 30
20
+ append = (file != 1)
21
+
22
+ for n in num_objects_list:
23
+ max_obj = n*2
24
+ for img_index in range(num_images):
25
+ #im = Image.open(os.path.join(input_dir, f"bg_{img_index+1}.png"))
26
+ fig, ax = plt.subplots()
27
+ #ax.imshow(im)
28
+ ax.set_aspect('equal')
29
+ plt.axis('off')
30
+
31
+ # Adjust plot limits to prevent cutoff
32
+ plt.xlim(-1500, 1500)
33
+ plt.ylim(-1000, 1000)
34
+
35
+ # Generate random positions for the shapes
36
+ positions = []
37
+ radius = 75
38
+ shapes = ['triangle', 'rectangle', 'pentagon']
39
+ colours = ['red', 'green', 'blue']
40
+ height, width = 1000, 1500
41
+ gold_answer = set()
42
+ for i in range(max_obj):
43
+ while True:
44
+ x, y = random.randint(-(width - radius), (width - radius)), random.randint(-(height - radius), (height-radius))
45
+ # Ensure shapes don't overlap
46
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
47
+ positions.append((x, y))
48
+ break
49
+
50
+ # Choose one odd-colored shape
51
+ #odd_index = random.randint(0, n - 1)
52
+
53
+ # Draw shapes and label them
54
+ circle, tri, rect, pent = [], [], [], []
55
+ shape_types = []
56
+ for _ in range(max_obj):
57
+ shape_types.append(random.choice(shapes))
58
+ indices = random.sample(range(0, max_obj), n)
59
+ for index in indices:
60
+ shape_types[index] = 'circle'
61
+
62
+ for i, (x, y) in enumerate(positions):
63
+ color = random.choice(colours)
64
+ shape_type = shape_types[i]
65
+
66
+ if shape_type == 'circle':
67
+ shape = plt.Circle((x, y), radius, color=color)
68
+ circle.append(str(i+1))
69
+ elif shape_type == 'triangle':
70
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
71
+ shape = plt.Polygon(triangle, color=color)
72
+ tri.append(str(i+1))
73
+ elif shape_type == 'rectangle':
74
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color)
75
+ rect.append(str(i+1))
76
+ elif shape_type == 'pentagon':
77
+ pentagon = np.array([
78
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
79
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
80
+ [x - 0.95 * radius, y + 0.31 * radius]
81
+ ])
82
+ shape = plt.Polygon(pentagon, color=color)
83
+ pent.append(str(i+1))
84
+
85
+ ax.add_patch(shape)
86
+ ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
87
+
88
+ # Save the plot to a file
89
+ filename = f"{file}.png"
90
+ file += 1
91
+ filepath = os.path.join(output_dir, filename)
92
+ plt.savefig(filepath, bbox_inches='tight')
93
+ plt.close()
94
+
95
+ gold_output = {
96
+ "id": filename,
97
+ "circles": sorted(circle),
98
+ "triangles": sorted(tri),
99
+ "rectangles": sorted(rect),
100
+ "pentagons": sorted(pent),
101
+ "num_objects": n
102
+ }
103
+ data.append(gold_output)
104
+
105
+
106
+ if append:
107
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
108
+ old_data = json.load(f)
109
+ old_data.extend(data)
110
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
111
+ json.dump(old_data, f, indent=2)
112
+ else:
113
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
114
+ json.dump(data, f, indent=2)
115
+
116
+
117
+
118
+ # # Example usage
119
+ # generate_shapes(10, 'shapes.png')
120
+ if __name__ == "__main__":
121
+ # Parse command line arguments
122
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
123
+ parser.add_argument(
124
+ '--num_images',
125
+ type=int,
126
+ help='Number of images to generate',
127
+ default=1
128
+ )
129
+ parser.add_argument(
130
+ '--num_sizes',
131
+ nargs='*',
132
+ type=int,
133
+ help='List of count of objects',
134
+ default=[5]
135
+ )
136
+ parser.add_argument(
137
+ '--file',
138
+ type=int,
139
+ help='Starting file number',
140
+ default=1
141
+ )
142
+ args = parser.parse_args()
143
+ file = args.file
144
+ num_object_list = args.num_sizes
145
+ append = (file != 1)
146
+ generate_shapes(args.num_images, num_object_list , file)
sort_circles/script.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+
7
+ def generate_circles(num_circles, min_size_diff=0.05):
8
+ # Create a figure
9
+ global file
10
+ fig, ax = plt.subplots(figsize=(num_circles * 3, 5))
11
+
12
+ # Data to store the circles' information
13
+ circles_info = []
14
+
15
+ # X-axis positions to ensure the circles are aligned horizontally
16
+ x_position = 0
17
+
18
+ # Store previously generated sizes to ensure minimum difference between sizes
19
+ radii = [0]
20
+
21
+ for i in range(1, num_circles + 1):
22
+ # Generate a random radius ensuring no two are too close in size
23
+ while True:
24
+ radius = random.uniform(0.3, 2) # Random size for the circle
25
+ if all(abs(radius - r) >= min_size_diff for r in radii):
26
+ radii.append(radius)
27
+ break
28
+
29
+ x_position += radius + radii[-2] + 0.5 # X-position for the circle
30
+ y = 2 # Y-position for alignment (all circles in a line)
31
+
32
+ # Plot the circle
33
+ circle = plt.Circle((x_position, y), radius, color='black', fill=True)
34
+ ax.add_patch(circle)
35
+
36
+ # Label the circle
37
+ ax.text(x_position, y, f'{i}', ha='center', va='center', fontsize=24, color='white')
38
+
39
+ # Store the circle's label and size
40
+ circles_info.append({'label': i , 'size': radius})
41
+
42
+ # Set limits and hide axes
43
+ ax.set_xlim(0, x_position + 2)
44
+ ax.set_ylim(0, 4)
45
+ ax.set_aspect('equal')
46
+ ax.axis('off')
47
+
48
+ image_filename = f"{file}.png"
49
+ image_path = os.path.join(output_dir, image_filename)
50
+ plt.savefig(image_path, bbox_inches='tight')
51
+ plt.close(fig)
52
+
53
+ return circles_info
54
+
55
+ def sort_circles(circles_info):
56
+ # Sort the circles based on their size
57
+ sorted_circles = sorted(circles_info, key=lambda x: x['size'])
58
+
59
+ # Print the gold output
60
+ # print("Gold output (sorted by size):")
61
+ # for circle in sorted_circles:
62
+ # print(f"{circle['label']}: Size {circle['size']:.2f}")
63
+
64
+ return sorted_circles
65
+
66
+ # def main():
67
+ # num_circles = 5 # Specify the number of circles to generate
68
+ # circles_info = generate_circles(num_circles) # Generate the circles and store their info
69
+
70
+ # # Sort the circles by size and get the gold output
71
+ # gold_output = sort_circles(circles_info)
72
+
73
+
74
+
75
+ # return gold_output
76
+ # Optionally, you can save this output to a file or use it for further processing
77
+
78
+ if __name__ == "__main__":
79
+ output_dir = os.path.join(os.getcwd(), "data")
80
+ if not os.path.exists(output_dir):
81
+ os.makedirs(output_dir)
82
+ # file = 1
83
+ # num_images = int(sys.argv[1])
84
+ # num_object_list = sys.argv[2:]
85
+ # num_object_list = [int(num_objects) for num_objects in num_object_list]
86
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
87
+ parser.add_argument(
88
+ '--num_images',
89
+ type=int,
90
+ help='Number of images to generate',
91
+ default=1
92
+ )
93
+ parser.add_argument(
94
+ '--num_sizes',
95
+ nargs='*',
96
+ help='List of n values',
97
+ type=int,
98
+ default=[5 , 3]
99
+ )
100
+ parser.add_argument(
101
+ '--file',
102
+ type=int,
103
+ help='Starting file number',
104
+ default=1
105
+ )
106
+ args = parser.parse_args()
107
+ file = args.file
108
+ num_object_list = args.num_sizes
109
+ num_images = args.num_images
110
+ append = (file != 1)
111
+ data = []
112
+ # main()/
113
+ for num_circles in num_object_list:
114
+ for _ in range(num_images):
115
+ circles_info = generate_circles(num_circles)
116
+ output = sort_circles(circles_info)
117
+ # Store the number of objects in the image_data dictionary
118
+ gold_output = [circle['label'] for circle in output]
119
+ gold_output = {
120
+ "id": f'{file}.png',
121
+ "Gold_output": gold_output,
122
+ "Rows" : num_circles
123
+ }
124
+ file += 1
125
+ data.append(gold_output)
126
+
127
+ if append:
128
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
129
+ old_data = json.load(f)
130
+ old_data.extend(data)
131
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
132
+ json.dump(old_data, f, indent=2)
133
+ else:
134
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
135
+ json.dump(data, f, indent=2)
sort_lines/script.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+
7
+ def generate_parallel_lines(n=5, image_size=(1000, 1000) , min_size_diff=20):
8
+
9
+ global file
10
+
11
+ canvas = Image.new("RGB", image_size, (255, 255, 255))
12
+ draw = ImageDraw.Draw(canvas)
13
+
14
+ line_spacing = image_size[0] // (n + 1)
15
+ base_y = image_size[1] - 10 # Common base for all lines
16
+
17
+ min_length = image_size[1] // 4
18
+ max_length = image_size[1] - 40
19
+
20
+ lengths = []
21
+ # prev_length = random.randint(min_length, max_length)
22
+ # lengths.append(prev_length)
23
+
24
+ for _ in range(0, n):
25
+ new_length = random.randint(min_length, max_length)
26
+ # for prev_length in lengths:
27
+ # while abs(new_length - prev_length) < min_size_diff:
28
+ # new_length = random.randint(min_length, max_length)
29
+ # lengths.append(new_length)
30
+ # prev_length = new_length
31
+ #Check all length in lengths for minimumm size difference
32
+ while any([abs(new_length - prev_length) < min_size_diff for prev_length in lengths]):
33
+ new_length = random.randint(min_length, max_length)
34
+ lengths.append(new_length)
35
+
36
+
37
+ for i in range(n):
38
+ x = (i + 1) * line_spacing
39
+ line_length = lengths[i]
40
+ start_y = base_y - line_length
41
+ end_y = base_y
42
+ color = (random.randint(50, 205), random.randint(50, 205), random.randint(50, 205))
43
+
44
+ draw.line([(x, start_y), (x, end_y)], fill=color, width=3)
45
+ font = ImageFont.truetype('ARIAL.ttf', 30)
46
+ draw.text((x - 10, start_y - 30), f"{i+1}", fill=(0, 0, 0), font=font)
47
+
48
+ to_sort = [{"label": i+1, "length": lengths[i]} for i in range(n)]
49
+ sorted_lines = sorted(to_sort, key=lambda x: x['length'])
50
+ gold_output = sorted_lines
51
+
52
+ image_filename = f"{file}.png"
53
+ image_path = os.path.join(output_dir, image_filename)
54
+ canvas.save(image_path)
55
+
56
+ return gold_output
57
+
58
+
59
+ if __name__ == "__main__":
60
+ output_dir = os.path.join(os.getcwd(), "data")
61
+ if not os.path.exists(output_dir):
62
+ os.makedirs(output_dir)
63
+ parser = argparse.ArgumentParser(description='Create a grid of circles and triangles.')
64
+ parser.add_argument(
65
+ '--num_images',
66
+ type=int,
67
+ help='Number of images to generate',
68
+ default=1
69
+ )
70
+ parser.add_argument(
71
+ '--num_sizes',
72
+ nargs='*',
73
+ help='List of n values',
74
+ type=int,
75
+ default=[5]
76
+ )
77
+ parser.add_argument(
78
+ '--file',
79
+ type=int,
80
+ help='Starting file number',
81
+ default=1
82
+ )
83
+ args = parser.parse_args()
84
+ file = args.file
85
+ num_object_list = args.num_sizes
86
+ num_images = args.num_images
87
+ append = (file != 1)
88
+ data = []
89
+ for num_circles in num_object_list:
90
+ for _ in range(num_images):
91
+ output = generate_parallel_lines(num_circles)
92
+ gold_output = [circle['label'] for circle in output]
93
+ gold_output = {
94
+ "id": f'{file}.png',
95
+ "Gold_output": gold_output,
96
+ "Lines" : num_circles
97
+ }
98
+ file += 1
99
+ data.append(gold_output)
100
+
101
+ if append:
102
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
103
+ old_data = json.load(f)
104
+ old_data.extend(data)
105
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
106
+ json.dump(old_data, f, indent=2)
107
+ else:
108
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
109
+ json.dump(data, f, indent=2)
vanishing_objects/script.py ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw
2
+ import random
3
+ import os
4
+ import json
5
+ import argparse
6
+
7
+ num_circle = 0
8
+ num_triangle = 0
9
+ num_square = 0
10
+ num_vanished = 0
11
+
12
+ def random_shape2(draw, shape_type, x, y, size, flag):
13
+ """
14
+ Draw a random shape on the provided image.
15
+ """
16
+ global num_circle, num_square, num_triangle, num_vanished
17
+ #probability = random.uniform(0.0, 1.0)
18
+ if shape_type == "circle":
19
+ if flag == False:
20
+ draw.ellipse([x - size, y - size, x + size, y + size], fill="black")
21
+ else:
22
+ draw.ellipse([x - size, y - size, x + size, y + size], fill="white")
23
+ num_vanished += 1
24
+ elif shape_type == "square":
25
+ if flag == False:
26
+ draw.rectangle([x - size, y - size, x + size, y + size], fill="black")
27
+ else:
28
+ draw.rectangle([x - size, y - size, x + size, y + size], fill="white")
29
+ num_vanished += 1
30
+ elif shape_type == "triangle":
31
+ points = [
32
+ (x, y - size), # Top
33
+ (x - size, y + size), # Bottom left
34
+ (x + size, y + size), # Bottom right
35
+ ]
36
+ if flag == False:
37
+ draw.polygon(points, fill="black")
38
+ else:
39
+ draw.polygon(points, fill="white")
40
+ num_vanished += 1
41
+
42
+ def random_shape(draw, shape_type, x, y, size):
43
+ """
44
+ Draw a random shape on the provided image.
45
+ """
46
+ global num_circle, num_square, num_triangle
47
+ if shape_type == "circle":
48
+ draw.ellipse([x - size, y - size, x + size, y + size], fill="black")
49
+ num_circle +=1
50
+ elif shape_type == "square":
51
+ draw.rectangle([x - size, y - size, x + size, y + size], fill="black")
52
+ num_square +=1
53
+ elif shape_type == "triangle":
54
+ points = [
55
+ (x, y - size), # Top
56
+ (x - size, y + size), # Bottom left
57
+ (x + size, y + size), # Bottom right
58
+ ]
59
+ draw.polygon(points, fill="black")
60
+ num_triangle +=1
61
+
62
+ def create_images(num_images, num_objects_list , file):
63
+ # Ensure the output directory exists
64
+ global num_circle, num_square, num_triangle, num_vanished
65
+ output_dir = os.path.join(os.getcwd(), "data")
66
+ if not os.path.exists(output_dir):
67
+ os.makedirs(output_dir)
68
+
69
+ data = []
70
+ image_width, image_height = 1500, 1000
71
+ append = (file != 1)
72
+ #max_obj = 30
73
+ for num_objects in num_objects_list:
74
+ max_obj = num_objects*2
75
+ for img_index in range(num_images):
76
+ # Create a blank white image
77
+ image = Image.new("RGB", (image_width, image_height), "white")
78
+ draw = ImageDraw.Draw(image)
79
+
80
+ # List to hold positions and sizes of shapes
81
+ shapes = []
82
+ num_circle =0
83
+ num_triangle = 0
84
+ num_square = 0
85
+ num_vanished = 0
86
+
87
+
88
+ # Possible shape types
89
+ shape_types = ["circle", "square", "triangle"]
90
+
91
+ while len(shapes) < max_obj:
92
+ shape_type = random.choice(shape_types)
93
+ size = random.randint(15, 30)
94
+ x = random.randint(size+50, image_width - size - 50)
95
+ y = random.randint(size + 50, image_height - size - 50)
96
+
97
+ # Check if the new shape overlaps or touches any existing shapes
98
+ overlap = False
99
+ for (sx, sy, ssize,_) in shapes:
100
+ distance = ((sx - x) ** 2 + (sy - y) ** 2) ** 0.5
101
+ if distance < (ssize + size)*1.5:
102
+ overlap = True
103
+ break
104
+
105
+ if not overlap:
106
+ shapes.append((x, y, size, shape_type))
107
+ # print(shapes)
108
+ # Draw the shapes
109
+ for (x, y, size, shape_type) in shapes:
110
+ random_shape(draw, shape_type, x, y, size)
111
+
112
+ # Save the image with the filename `i.png`
113
+ image_filename = f"first{file}.png"
114
+ image_path = os.path.join(output_dir, image_filename)
115
+ image.save(image_path)
116
+
117
+ indices = random.sample(range(0, max_obj), num_objects)
118
+ for i, (x, y, size, shape_type) in enumerate(shapes):
119
+ flag = False
120
+ if i in indices:
121
+ flag = True
122
+ random_shape2(draw, shape_type, x, y, size, flag)
123
+
124
+ image_filename2 = f"second{file}.png"
125
+ file += 1
126
+ image_path2 = os.path.join(output_dir, image_filename2)
127
+ image.save(image_path2)
128
+
129
+ # Store the number of objects in the data dictionary
130
+ gold_output = {
131
+ "id": image_filename2,
132
+ "circles" : num_circle,
133
+ "squares" : num_square,
134
+ "triangles" : num_triangle,
135
+ "vanished" : num_vanished
136
+ }
137
+ data.append(gold_output)
138
+
139
+ # Save the data to a JSON file
140
+ if append:
141
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
142
+ old_data = json.load(f)
143
+ old_data.extend(data)
144
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
145
+ json.dump(old_data, f, indent=2)
146
+ else:
147
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
148
+ json.dump(data, f, indent=2)
149
+
150
+ if __name__ == "__main__":
151
+ parser = argparse.ArgumentParser(description='Create an image of different shapes')
152
+ parser.add_argument(
153
+ '--num_images',
154
+ type=int,
155
+ help='Number of images to generate',
156
+ default=1
157
+ )
158
+ parser.add_argument(
159
+ '--num_sizes',
160
+ nargs='*',
161
+ type=int,
162
+ help='List of total number of objects',
163
+ default=[5]
164
+ )
165
+ parser.add_argument(
166
+ '--file',
167
+ type=int,
168
+ help='Starting file number',
169
+ default=1
170
+ )
171
+ args = parser.parse_args()
172
+ file = args.file
173
+ num_object_list = args.num_sizes
174
+ # print(num_object_list)
175
+ # Create images with the specified number of objects
176
+ create_images(args.num_images, num_object_list , file)
water_image/script.py ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import cv2
3
+ import PIL
4
+ from PIL import Image
5
+ import random
6
+ import numpy as np
7
+ import os
8
+ import json
9
+ import argparse
10
+
11
+ def generate_shapes(num_images, num_objects_list , file):
12
+ # Set up the plot
13
+
14
+ output_dir = os.path.join(os.getcwd(), "data")
15
+ if not os.path.exists(output_dir):
16
+ os.makedirs(output_dir)
17
+
18
+ data = []
19
+ append = (file != 1)
20
+
21
+ for n in num_objects_list:
22
+ max_obj = 2*n
23
+ for img_index in range(num_images):
24
+ """fig, ax = plt.subplots()
25
+ ax.set_aspect('equal')
26
+ plt.axis('off')
27
+
28
+ # Adjust plot limits to prevent cutoff
29
+ plt.xlim(-0.1, 1.1)
30
+ plt.ylim(-0.1, 1.1)
31
+
32
+ # Generate random positions for the shapes
33
+ positions = []
34
+ radius = 0.05
35
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
36
+ colours = ['red', 'green', 'blue', 'yellow', 'orange', 'black']
37
+ for i in range(n):
38
+ while True:
39
+ x, y = random.uniform(0.1, 0.9), random.uniform(0.1, 0.9)
40
+ # Ensure shapes don't overlap
41
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
42
+ positions.append((x, y))
43
+ break
44
+
45
+ # Choose one odd-colored shape
46
+ #odd_index = random.randint(0, n - 1)
47
+
48
+ # Draw shapes and label them
49
+ for i, (x, y) in enumerate(positions):
50
+ color = random.choice(colours)
51
+ shape_type = random.choice(shapes)
52
+
53
+ if shape_type == 'circle':
54
+ shape = plt.Circle((x, y), radius, color=color)
55
+ elif shape_type == 'triangle':
56
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
57
+ shape = plt.Polygon(triangle, color=color)
58
+ elif shape_type == 'rectangle':
59
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color)
60
+ elif shape_type == 'pentagon':
61
+ pentagon = np.array([
62
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
63
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
64
+ [x - 0.95 * radius, y + 0.31 * radius]
65
+ ])
66
+ shape = plt.Polygon(pentagon, color=color)
67
+
68
+ ax.add_patch(shape)"""
69
+ #ax.text(x, y, str(i + 1), color='white', ha='center', va='center', fontsize=8, weight='bold')
70
+
71
+ # Save the plot to a file
72
+ fig, ax = plt.subplots()
73
+ ax.set_aspect('equal')
74
+ plt.axis('off')
75
+
76
+ # Adjust plot limits to prevent cutoff
77
+ plt.xlim(-203.5, 203.5)
78
+ plt.ylim(-203.5, 203.5)
79
+
80
+ # Generate random positions for the shapes
81
+ positions = []
82
+ radius = 3.5
83
+ shapes = ['circle', 'triangle', 'rectangle', 'pentagon']
84
+ colours = ['red', 'green', 'blue', 'yellow', 'orange', 'black']
85
+ for i in range(max_obj):
86
+ while True:
87
+ x, y = random.uniform(-200, 200), random.uniform(3.5, 200)
88
+ # Ensure shapes don't overlap
89
+ if all(((x - px) ** 2 + (y - py) ** 2) ** 0.5 > 2 * radius for px, py in positions):
90
+ positions.append((x, y))
91
+ break
92
+
93
+ # Choose one odd-colored shape
94
+ #odd_index = random.randint(0, n - 1)
95
+
96
+ # Draw shapes and label them
97
+ color, shape_type = [], []
98
+ plt.axhline(y = 0, color = 'blue')
99
+ for i, (x, y) in enumerate(positions):
100
+ color.append(random.choice(colours))
101
+ shape_type.append(random.choice(shapes))
102
+
103
+ if shape_type[-1] == 'circle':
104
+ shape = plt.Circle((x, y), radius, color=color[-1])
105
+ elif shape_type[-1] == 'triangle':
106
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
107
+ shape = plt.Polygon(triangle, color=color[-1])
108
+ elif shape_type[-1] == 'rectangle':
109
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color[-1])
110
+ elif shape_type[-1] == 'pentagon':
111
+ pentagon = np.array([
112
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
113
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
114
+ [x - 0.95 * radius, y + 0.31 * radius]
115
+ ])
116
+ shape = plt.Polygon(pentagon, color=color[-1])
117
+
118
+ ax.add_patch(shape)
119
+ filename = f"first{file}.png"
120
+ filepath = os.path.join(output_dir, filename)
121
+ plt.savefig(filepath, bbox_inches='tight')
122
+ plt.close()
123
+
124
+ fig, ax = plt.subplots()
125
+ ax.set_aspect('equal')
126
+ plt.axis('off')
127
+
128
+ # Adjust plot limits to prevent cutoff
129
+ plt.xlim(-203.5, 203.5)
130
+ plt.ylim(-203.5, 203.5)
131
+
132
+ for i in range(n):
133
+ x = list(positions[i])
134
+ x[1] = -x[1]
135
+ positions[i] = tuple(x)
136
+
137
+ plt.axhline(y = 0, color = 'blue')
138
+ for i, (x, y) in enumerate(positions):
139
+ if shape_type[i] == 'circle':
140
+ shape = plt.Circle((x, y), radius, color=color[i])
141
+ elif shape_type[i] == 'triangle':
142
+ triangle = np.array([[x, y + radius], [x - radius, y - radius], [x + radius, y - radius]])
143
+ shape = plt.Polygon(triangle, color=color[i])
144
+ elif shape_type[i] == 'rectangle':
145
+ shape = plt.Rectangle((x - radius, y - radius), 2 * radius, 2 * radius, color=color[i])
146
+ elif shape_type[i] == 'pentagon':
147
+ pentagon = np.array([
148
+ [x, y + radius], [x + 0.95 * radius, y + 0.31 * radius],
149
+ [x + 0.59 * radius, y - 0.81 * radius], [x - 0.59 * radius, y - 0.81 * radius],
150
+ [x - 0.95 * radius, y + 0.31 * radius]
151
+ ])
152
+ shape = plt.Polygon(pentagon, color=color[i])
153
+
154
+ ax.add_patch(shape)
155
+ filename = f"second{file}.png"
156
+ file += 1
157
+ filepath = os.path.join(output_dir, filename)
158
+ plt.savefig(filepath, bbox_inches='tight')
159
+ plt.close()
160
+
161
+ gold_answer = n
162
+ """if choice == 0:
163
+ img = cv2.imread(filepath)
164
+ img_mirror = np.flip(img, axis=1)
165
+ cv2.imwrite(os.path.join(output_dir, f"second{file-1}.png"), img_mirror)
166
+ gold_answer = "Yes"
167
+ else:
168
+ angles = [90, 180, 270, 360]
169
+ angle = random.choice(angles)
170
+ img = Image.open(filepath)
171
+ rotated_image = img.rotate(angle, PIL.Image.BILINEAR)
172
+ rotated_image.save(os.path.join(output_dir, f"second{file-1}.png"), "PNG")
173
+ gold_answer = "No"
174
+
175
+ """
176
+
177
+
178
+ gold_output = {
179
+ "id": filename,
180
+ "water_image": gold_answer,
181
+ "num_objects": n
182
+ }
183
+ data.append(gold_output)
184
+
185
+
186
+ if append:
187
+ with open(os.path.join(os.getcwd() , "data.json"), "r") as f:
188
+ old_data = json.load(f)
189
+ old_data.extend(data)
190
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
191
+ json.dump(old_data, f, indent=2)
192
+ else:
193
+ with open(os.path.join(os.getcwd() , "data.json"), "w") as f:
194
+ json.dump(data, f, indent=2)
195
+
196
+
197
+
198
+ # # Example usage
199
+ # generate_shapes(10, 'shapes.png')
200
+ if __name__ == "__main__":
201
+ # Parse command line arguments
202
+ parser = argparse.ArgumentParser(description='Create an image of different objects')
203
+ parser.add_argument(
204
+ '--num_images',
205
+ type=int,
206
+ help='Number of images to generate',
207
+ default=1
208
+ )
209
+ parser.add_argument(
210
+ '--num_sizes',
211
+ nargs='*',
212
+ type=int,
213
+ help='List of count of objects',
214
+ default=[5]
215
+ )
216
+ parser.add_argument(
217
+ '--file',
218
+ type=int,
219
+ help='Starting file number',
220
+ default=1
221
+ )
222
+ args = parser.parse_args()
223
+ file = args.file
224
+ num_object_list = args.num_sizes
225
+ append = (file != 1)
226
+ generate_shapes(args.num_images, num_object_list , file)