Skip to content

Commit 6238f02

Browse files
committed
PNG to JPG and other changes in resize
1 parent d1c82cd commit 6238f02

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

notebooks/resize.ipynb

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"id": "ab143ef4-f298-46ed-b4ba-4ae1a8b15154",
77
"metadata": {},
88
"outputs": [],
@@ -193,20 +193,90 @@
193193
" resize_images_uav(input_paths[i], output_paths[i])"
194194
]
195195
},
196+
{
197+
"cell_type": "markdown",
198+
"id": "05832748-102f-4742-ab5c-4ef9ed455b5b",
199+
"metadata": {},
200+
"source": [
201+
"Convert Nearmap Images from PNG to JPG"
202+
]
203+
},
204+
{
205+
"cell_type": "code",
206+
"execution_count": 2,
207+
"id": "fed8594e-3475-4f09-a92d-fd9d3f771703",
208+
"metadata": {},
209+
"outputs": [],
210+
"source": [
211+
"data_root = \"/home/gridsan/aray/meng/mmsegmentation/data/dataset_mmseg\" #ANUSHKA"
212+
]
213+
},
214+
{
215+
"cell_type": "code",
216+
"execution_count": 11,
217+
"id": "ff8b40ac-de73-4a7e-8427-a9a037c4ef55",
218+
"metadata": {},
219+
"outputs": [],
220+
"source": [
221+
"nearmap_img = os.path.join(data_root, \"img_dir_nearmap/\")\n",
222+
"output_img = os.path.join(data_root, \"img_dir_nearmap_jpg/\")\n",
223+
"nearmap_ann = os.path.join(data_root, \"ann_dir_nearmap/\")\n",
224+
"output_ann = os.path.join(data_root, \"ann_dir_nearmap_jpg/\")"
225+
]
226+
},
227+
{
228+
"cell_type": "code",
229+
"execution_count": 3,
230+
"id": "8fc18838-7b7a-489f-a13c-b95e165dfe06",
231+
"metadata": {},
232+
"outputs": [],
233+
"source": [
234+
"#UAV Directories \n",
235+
"uav_img = os.path.join(data_root, \"img_dir_uav/\")\n",
236+
"output_img = os.path.join(data_root, \"img_dir_uav_jpg/\")"
237+
]
238+
},
239+
{
240+
"cell_type": "code",
241+
"execution_count": 4,
242+
"id": "61e4bdda-e3c5-4c7e-92d9-0df4986c0c81",
243+
"metadata": {},
244+
"outputs": [],
245+
"source": [
246+
"def change_jpg(path, output):\n",
247+
" sub_dirs = ['train/', 'test/', 'val/']\n",
248+
" for sub_dir in sub_dirs:\n",
249+
" dirs = os.listdir(path+sub_dir)\n",
250+
" for item in dirs:\n",
251+
" if os.path.isfile(path+sub_dir+item):\n",
252+
" im = Image.open(path+sub_dir+item)\n",
253+
" im = im.convert('RGB')\n",
254+
" filename = item.split('.')[0]\n",
255+
" im.save(output+sub_dir+filename+'.jpg')\n",
256+
"\n",
257+
"# dirs = [uav_img, nearmap_ann]\n",
258+
"# outputs = [output_img, output_ann]\n",
259+
"# for i in range(len(dirs)):\n",
260+
"# change_jpg(dirs[i], outputs[i])\n",
261+
" \n",
262+
"change_jpg(uav_img, output_img)\n",
263+
"\n"
264+
]
265+
},
196266
{
197267
"cell_type": "code",
198268
"execution_count": null,
199-
"id": "666617ee-782a-4bf2-b49c-53bb83ee3830",
269+
"id": "1de781eb-7d84-4a17-94d9-23f067537023",
200270
"metadata": {},
201271
"outputs": [],
202272
"source": []
203273
}
204274
],
205275
"metadata": {
206276
"kernelspec": {
207-
"display_name": "open-mmlab",
277+
"display_name": "Python 3",
208278
"language": "python",
209-
"name": "open-mmlab"
279+
"name": "python3"
210280
},
211281
"language_info": {
212282
"codemirror_mode": {

0 commit comments

Comments
 (0)