init
Master
Bases: Palette
Source code in phomo/master.py
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 |
|
img
property
PIL.Image
of the master image.
pixels: np.ndarray
property
Array containing the 3-channel pixel values of the master image.
__init__(array)
The master image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
ndarray
|
numpy array of the image, should contain 3 channels. |
required |
Returns:
Type | Description |
---|---|
None
|
Master image instance. |
Source code in phomo/master.py
60 61 62 63 64 65 66 67 68 69 |
|
from_file(master_image_file, crop_ratio=None, img_size=None, mode=None)
classmethod
Create a master image from file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master_image_file |
PathLike
|
path to image file. |
required |
crop_ratio |
Optional[float]
|
width to height ratio to crop the master image to. 1 results in a square image. |
None
|
img_size |
Optional[Tuple[int, int]]
|
resize the image to the provided size, width followed by height. |
None
|
mode |
Optional[str]
|
convert the image to the provided mode. See PIL Modes. |
None
|
Returns:
Type | Description |
---|---|
Master
|
Master image instance. |
Examples:
For black and white square 1280x1280 image.
>>> Master.from_file("master.png", crop_ratio=1, img_size=(1280, 1280), convert="L")
Source code in phomo/master.py
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 |
|
from_image(master_image)
classmethod
Create a master image from PIL.Image.Image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master_image |
Image
|
|
required |
Returns:
Type | Description |
---|---|
Master
|
Master image instance. |
Source code in phomo/master.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
Mosaic
Source code in phomo/mosaic.py
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
n_leftover: int
property
The number of tiles which will be unused when building the mosaic.
size: Tuple[int, int]
property
The size of the mosaic image.
It can be different from the master image size as an integer number of tiles should fit within it.
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
The width and height of the mosaic image. |
__init__(master, pool, n_appearances=1)
Construct a regular grid mosaic.
Note
The Pool's tiles should all be the same size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master |
Master
|
|
required |
pool |
Pool
|
Tile image pool with which to reconstruct the |
required |
n_appearances |
int
|
Number of times a tile can appear in the mosaic. |
1
|
Examples:
Building a mosaic.
>>> pool = Pool.from_dir("tiles")
>>> master = Master.from_file("master.png")
>>> mosaic = Mosaic(master, pool, n_appearances=1)
>>> mosaic.build(mosaic.d_matrix())
Source code in phomo/mosaic.py
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 |
|
build(d_matrix)
Construct the mosaic image by solving the linear sum assignment problem. See: https://en.wikipedia.org/wiki/Assignment_problem
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d_matrix |
ndarray
|
The computed distance matrix. |
required |
Returns:
Type | Description |
---|---|
Image
|
The |
Examples:
Building a mosaic.
>>> mosaic.build(mosaic.d_matrix())
On a GPU.
>>> mosaic.build(mosaic.d_matrix_cuda())
Source code in phomo/mosaic.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
|
build_greedy(d_matrix)
Construct the mosaic image using a greedy tile assignement algorithm.
This leads to less accurate mosaics, but is significantly faster than the optimal assignement algorithm, especialy when the distance matrix is large.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d_matrix |
ndarray
|
The computed distance matrix. |
required |
Returns:
Type | Description |
---|---|
Image
|
The |
Source code in phomo/mosaic.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
d_matrix(workers=1, metric='norm', **kwargs)
Compute the distance matrix between all the master's tiles and the pool tiles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workers |
int
|
The number of worker to use. |
1
|
metric |
Union[str, MetricCallable]
|
The distance metric used for the distance matrix. Either
provide a string, for implemented metrics see |
'norm'
|
**kwargs |
Passed to |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
Distance matrix, shape: (number of master arrays, number of tiles in the pool). |
Source code in phomo/mosaic.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
d_matrix_cuda(metric='norm')
Compute the distance matrix using CUDA for GPU acceleration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric |
str
|
The distance metric used for the distance matrix. Either "norm" or "greyscale". |
'norm'
|
Returns:
Type | Description |
---|---|
ndarray
|
Distance matrix, shape: (number of master arrays, number of tiles in the pool). |
Source code in phomo/mosaic.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
from_file_and_dir(master_file, tile_dir, *args, master_crop_ratio=None, master_size=None, master_mode=None, tile_crop_ratio=None, tile_size=None, tile_mode=None, **kwargs)
classmethod
Construct a Mosaic
from a master image file and a directory containing the file images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master_file |
PathLike
|
The master image file. |
required |
tile_dir |
PathLike
|
the directory containing the tile images. |
required |
Returns:
Type | Description |
---|---|
Mosaic
|
A |
Source code in phomo/mosaic.py
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 |
|
Pool
Bases: Palette
Source code in phomo/pool.py
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 |
|
pixels: np.ndarray
property
Array containing the 3-channel pixel values of all the images in the Pool.
tiles: PoolTiles
property
Access the Pool's tile images.
Examples:
Show the first image in the pool.
>>> pool.tiles[0].show()
__init__(array)
A Pool
of tile images, to use in contructing the photo mosaic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
ArrayLike
|
|
required |
Source code in phomo/pool.py
68 69 70 71 72 73 74 75 76 77 |
|
from_dir(tile_dir, crop_ratio=None, tile_size=None, mode=None)
classmethod
Create a Pool
instance from the images in a directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tile_dir |
PathLike
|
path to directory containing the images. |
required |
crop_ratio |
Optional[float]
|
width to height ratio to crop the tile images to. 1 results in a square image. |
None
|
tile_size |
Optional[Tuple[int, int]]
|
resize the image to the provided size, width followed by height. |
None
|
mode |
Optional[str]
|
convert the images to the provided mode. See PIL Modes. |
None
|
Source code in phomo/pool.py
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 |
|
from_files(files, crop_ratio=None, tile_size=None, mode=None)
classmethod
Create a Pool
instance from a list of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
files |
Sequence[PathLike]
|
list of paths to the tile images. |
required |
crop_ratio |
Optional[float]
|
width to height ratio to crop the master image to. 1 results in a square image. |
None
|
tile_size |
Optional[Tuple[int, int]]
|
resize the image to the provided size, width followed by height. |
None
|
mode |
Optional[str]
|
mode the image to the provided mode. See PIL Modes. |
None
|
Source code in phomo/pool.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|