Commit
·
9fbbef8
1
Parent(s):
998873a
Upload 2 files
Browse files- filter.ipynb +16 -16
filter.ipynb
CHANGED
@@ -42,11 +42,11 @@
|
|
42 |
"testset = os.listdir(\"secondleg\")[8]\n",
|
43 |
"print(testset)\n",
|
44 |
"tiff = Image.open(pl.Path(\n",
|
45 |
-
" rf'
|
46 |
"csv = pd.read_csv(pl.Path(\n",
|
47 |
-
" rf'
|
48 |
"with open(pl.Path( \n",
|
49 |
-
" rf'
|
50 |
" offset = f.read() \n",
|
51 |
" if offset != '':\n",
|
52 |
" offset = int(offset)\n",
|
@@ -83,11 +83,11 @@
|
|
83 |
"\n",
|
84 |
"# opens the images, csvs and offset files and reads the needed data\n",
|
85 |
"tiff = Image.open(pl.Path(\n",
|
86 |
-
" rf'
|
87 |
"csv = pd.read_csv(pl.Path(\n",
|
88 |
-
" rf'
|
89 |
"with open(pl.Path(\n",
|
90 |
-
" rf'
|
91 |
" offset = f.read()\n",
|
92 |
" if offset == \"\":\n",
|
93 |
" offset = 0\n",
|
@@ -130,13 +130,13 @@
|
|
130 |
" print(testset)\n",
|
131 |
"\n",
|
132 |
" tiff = Image.open(pl.Path(\n",
|
133 |
-
" rf'
|
134 |
"\n",
|
135 |
" csv = pd.read_csv(pl.Path(\n",
|
136 |
-
" rf'
|
137 |
"\n",
|
138 |
" with open(pl.Path(\n",
|
139 |
-
" rf'
|
140 |
" offset = f.read()\n",
|
141 |
" if offset == \"\":\n",
|
142 |
" offset = 0\n",
|
@@ -153,7 +153,7 @@
|
|
153 |
"\n",
|
154 |
" # Save the cropped and converted image to the specified path\n",
|
155 |
" img.save(pl.Path(\n",
|
156 |
-
" rf'
|
157 |
"\n",
|
158 |
" # Add the offset to the specified columns of the csv file and reverse the order\n",
|
159 |
" csv = csv[[\"x_surface\", \"y_surface\", \"x_bed\", \"y_bed\"]]+offset\n",
|
@@ -201,7 +201,7 @@
|
|
201 |
"\n",
|
202 |
" # Save the image with the drawn polygons to the specified path\n",
|
203 |
" img.save(pl.Path(\n",
|
204 |
-
" rf'
|
205 |
]
|
206 |
},
|
207 |
{
|
@@ -216,10 +216,10 @@
|
|
216 |
"for testset in os.listdir(\"secondleg\"):\n",
|
217 |
"\n",
|
218 |
" cimg = Image.open(pl.Path(\n",
|
219 |
-
" rf'
|
220 |
"\n",
|
221 |
" mask = Image.open(pl.Path(\n",
|
222 |
-
" rf'
|
223 |
"\n",
|
224 |
" # Calculate the sections to crop the image into, with each section being 400 pixels wide and an overlap of 80 pixels\n",
|
225 |
" cropsection = window_with_remainder(400, 80, cimg.size[0])\n",
|
@@ -227,17 +227,17 @@
|
|
227 |
" # Try to create directories for the cropped images and masks\n",
|
228 |
" try:\n",
|
229 |
" os.mkdir(pl.Path(\n",
|
230 |
-
" rf'
|
231 |
"\n",
|
232 |
" os.mkdir(pl.Path(\n",
|
233 |
-
" rf'
|
234 |
" except:\n",
|
235 |
" pass\n",
|
236 |
"\n",
|
237 |
" for i in cropsection:\n",
|
238 |
" # Crop the image to the current section, resize it to 400x400, and save it to the specified path\n",
|
239 |
" cimg.crop((i[0], 0, i[1], cimg.size[1])).resize((400, 400)).save(pl.Path(\n",
|
240 |
-
" rf'
|
241 |
]
|
242 |
},
|
243 |
{
|
|
|
42 |
"testset = os.listdir(\"secondleg\")[8]\n",
|
43 |
"print(testset)\n",
|
44 |
"tiff = Image.open(pl.Path(\n",
|
45 |
+
" rf'.\\secondleg\\{testset}\\{testset}.tiff')) \n",
|
46 |
"csv = pd.read_csv(pl.Path(\n",
|
47 |
+
" rf'.\\secondleg\\{testset}\\{testset}.csv')) \n",
|
48 |
"with open(pl.Path( \n",
|
49 |
+
" rf'.\\secondleg\\{testset}\\offset.txt'),\"+x\") as f: \n",
|
50 |
" offset = f.read() \n",
|
51 |
" if offset != '':\n",
|
52 |
" offset = int(offset)\n",
|
|
|
83 |
"\n",
|
84 |
"# opens the images, csvs and offset files and reads the needed data\n",
|
85 |
"tiff = Image.open(pl.Path(\n",
|
86 |
+
" rf'.\\secondleg\\{testset}\\{testset}.tiff'))\n",
|
87 |
"csv = pd.read_csv(pl.Path(\n",
|
88 |
+
" rf'.\\secondleg\\{testset}\\{testset}.csv'))\n",
|
89 |
"with open(pl.Path(\n",
|
90 |
+
" rf'.\\secondleg\\{testset}\\offset.txt')) as f:\n",
|
91 |
" offset = f.read()\n",
|
92 |
" if offset == \"\":\n",
|
93 |
" offset = 0\n",
|
|
|
130 |
" print(testset)\n",
|
131 |
"\n",
|
132 |
" tiff = Image.open(pl.Path(\n",
|
133 |
+
" rf'.\\secondleg\\{testset}\\{testset}.tiff'))\n",
|
134 |
"\n",
|
135 |
" csv = pd.read_csv(pl.Path(\n",
|
136 |
+
" rf'.\\secondleg\\{testset}\\{testset}.csv'))\n",
|
137 |
"\n",
|
138 |
" with open(pl.Path(\n",
|
139 |
+
" rf'.\\secondleg\\{testset}\\offset.txt')) as f:\n",
|
140 |
" offset = f.read()\n",
|
141 |
" if offset == \"\":\n",
|
142 |
" offset = 0\n",
|
|
|
153 |
"\n",
|
154 |
" # Save the cropped and converted image to the specified path\n",
|
155 |
" img.save(pl.Path(\n",
|
156 |
+
" rf'.\\secondleg\\{testset}\\cropped_img_{testset}.png'))\n",
|
157 |
"\n",
|
158 |
" # Add the offset to the specified columns of the csv file and reverse the order\n",
|
159 |
" csv = csv[[\"x_surface\", \"y_surface\", \"x_bed\", \"y_bed\"]]+offset\n",
|
|
|
201 |
"\n",
|
202 |
" # Save the image with the drawn polygons to the specified path\n",
|
203 |
" img.save(pl.Path(\n",
|
204 |
+
" rf'.\\secondleg\\{testset}\\img_mask_{testset}.png'))"
|
205 |
]
|
206 |
},
|
207 |
{
|
|
|
216 |
"for testset in os.listdir(\"secondleg\"):\n",
|
217 |
"\n",
|
218 |
" cimg = Image.open(pl.Path(\n",
|
219 |
+
" rf'.\\secondleg\\{testset}\\cropped_img_{testset}.png'))\n",
|
220 |
"\n",
|
221 |
" mask = Image.open(pl.Path(\n",
|
222 |
+
" rf'.\\secondleg\\{testset}\\img_mask_{testset}.png'))\n",
|
223 |
"\n",
|
224 |
" # Calculate the sections to crop the image into, with each section being 400 pixels wide and an overlap of 80 pixels\n",
|
225 |
" cropsection = window_with_remainder(400, 80, cimg.size[0])\n",
|
|
|
227 |
" # Try to create directories for the cropped images and masks\n",
|
228 |
" try:\n",
|
229 |
" os.mkdir(pl.Path(\n",
|
230 |
+
" rf'.\\secondleg\\{testset}\\cropped_images'))\n",
|
231 |
"\n",
|
232 |
" os.mkdir(pl.Path(\n",
|
233 |
+
" rf'.\\secondleg\\{testset}\\cropped_masks'))\n",
|
234 |
" except:\n",
|
235 |
" pass\n",
|
236 |
"\n",
|
237 |
" for i in cropsection:\n",
|
238 |
" # Crop the image to the current section, resize it to 400x400, and save it to the specified path\n",
|
239 |
" cimg.crop((i[0], 0, i[1], cimg.size[1])).resize((400, 400)).save(pl.Path(\n",
|
240 |
+
" rf'\\secondleg\\{testset}\\cropped_images\\cimg-{testset}_{i[0]}_{i[1]}.png'))\n"
|
241 |
]
|
242 |
},
|
243 |
{
|