File size: 3,969 Bytes
436c9ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "5bdfe87c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import json\n",
    "from itertools import combinations\n",
    "IMAGE_DIR = \"/root/siton-tmp/images_divided\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb8c9036",
   "metadata": {},
   "outputs": [],
   "source": [
    "folders = sorted([\n",
    "    f for f in os.listdir(IMAGE_DIR)\n",
    "    if os.path.isdir(os.path.join(IMAGE_DIR, f)) and not f.startswith('.')\n",
    "])\n",
    "data = []\n",
    "for cnt, idx in enumerate(folders):\n",
    "    folder_path = os.path.join(IMAGE_DIR, idx)\n",
    "    images = sorted([img for img in os.listdir(folder_path) if img.endswith('.png')])\n",
    "    first_indices, second_indices = zip(*[\n",
    "        list(map(int, img.split('.')[0].split('_')))\n",
    "        for img in images\n",
    "    ])\n",
    "    first_indices = sorted(set(first_indices))\n",
    "    second_indices = sorted(set(second_indices))\n",
    "    \n",
    "    for i in first_indices:\n",
    "        for j in second_indices:\n",
    "            ref_img = f\"{i}_{j}.png\"\n",
    "            candidates = [\n",
    "                [\n",
    "                    f\"{x}_{y}.png\"\n",
    "                    for x in first_indices\n",
    "                ]\n",
    "                for y in second_indices if y != j\n",
    "            ]\n",
    "            items = [\n",
    "                {\n",
    "                'ref_image': ref_img,\n",
    "                'rank_images': cand,\n",
    "                'idx': idx,\n",
    "                } for cand in candidates\n",
    "            ]\n",
    "            data.extend(items)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "36e0603b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'ref_image': '0_0.png',\n",
       "  'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '0_0.png',\n",
       "  'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '0_1.png',\n",
       "  'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '0_1.png',\n",
       "  'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '0_2.png',\n",
       "  'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '0_2.png',\n",
       "  'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '1_0.png',\n",
       "  'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '1_0.png',\n",
       "  'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '1_1.png',\n",
       "  'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
       "  'idx': '0000'},\n",
       " {'ref_image': '1_1.png',\n",
       "  'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
       "  'idx': '0000'}]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[:10]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch-env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}