informatique:ign_bdortho
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| informatique:ign_bdortho [22/02/2026 11:48] – [Indre-et-Loire (37)] cyrille | informatique:ign_bdortho [23/02/2026 20:54] (Version actuelle) – [Outils] cyrille | ||
|---|---|---|---|
| Ligne 10: | Ligne 10: | ||
| * 20 cm en RVB au 01/01/2025 BDORTHO_2-0_RVB-0M20_JP2-E080_LAMB93_D037_2025-01-01 | * 20 cm en RVB au 01/01/2025 BDORTHO_2-0_RVB-0M20_JP2-E080_LAMB93_D037_2025-01-01 | ||
| * 7 fichiers 7z contenant des images au format JP2/ | * 7 fichiers 7z contenant des images au format JP2/ | ||
| - | * Décompressés on obtient images JP2 de 94 Mo chacune | + | * Décompressés on obtient |
| + | * 1 image découpée 640 pixels fait ~1520 fichiers pour ~70 Mo | ||
| + | * au final 459 342 fichiers pour 24 Go | ||
| + | |||
| + | ===== Outils ===== | ||
| + | |||
| + | P'tit script Python pour découper les JP2 en JPG 640 pixels pour Yolo: | ||
| + | |||
| + | <code python> | ||
| + | """ | ||
| + | |||
| + | Installation: | ||
| + | pip install rasterio pillow numpy tqdm | ||
| + | |||
| + | """ | ||
| + | import rasterio | ||
| + | import os | ||
| + | import glob | ||
| + | import shutil | ||
| + | from rasterio.windows import Window | ||
| + | from PIL import Image | ||
| + | import numpy as np | ||
| + | from tqdm import tqdm | ||
| + | from concurrent.futures import ThreadPoolExecutor, | ||
| + | |||
| + | def decouper_fichier_jp2(fichier, | ||
| + | nom_base = os.path.splitext(os.path.basename(fichier))[0] | ||
| + | sous_dossier = os.path.join(dossier_sortie, | ||
| + | os.makedirs(sous_dossier, | ||
| + | # Copie du fichier .tab correspondant | ||
| + | fichier_tab = fichier.replace(' | ||
| + | if os.path.exists(fichier_tab): | ||
| + | shutil.copy(fichier_tab, | ||
| + | # Découpe le fichier JP2 en tuiles JPG | ||
| + | with rasterio.open(fichier) as src: | ||
| + | h, w = src.shape | ||
| + | nb_tuiles_h = h // taille | ||
| + | nb_tuiles_w = w // taille | ||
| + | total_tuiles = nb_tuiles_h * nb_tuiles_w | ||
| + | # réserve un buffer pour limiter une allocation à chaque tuile. | ||
| + | buffer = np.empty((src.count, | ||
| + | with tqdm(total=total_tuiles, | ||
| + | for y in range(0, h, taille): | ||
| + | for x in range(0, w, taille): | ||
| + | window = Window(x, y, taille, taille) | ||
| + | if y + taille <= h and x + taille <= w: | ||
| + | tile = src.read(window=window, | ||
| + | tile_rgb = np.moveaxis(tile, | ||
| + | img = Image.fromarray(tile_rgb) | ||
| + | img.save(f" | ||
| + | pbar.update(1) | ||
| + | |||
| + | def decouper_jp2_en_tuiles_parallele(dossier_entree, | ||
| + | os.makedirs(dossier_sortie, | ||
| + | fichiers = glob.glob(os.path.join(dossier_entree, | ||
| + | #fichiers = glob.glob(os.path.join(dossier_entree, | ||
| + | with ThreadPoolExecutor(max_workers=nb_threads) as executor: | ||
| + | futures = [executor.submit(decouper_fichier_jp2, | ||
| + | for future in as_completed(futures): | ||
| + | future.result() | ||
| + | |||
| + | if __name__ == " | ||
| + | |||
| + | decouper_jp2_en_tuiles_parallele( | ||
| + | " | ||
| + | " | ||
| + | nb_threads=4, | ||
| + | ) | ||
| + | </ | ||
informatique/ign_bdortho.1771757319.txt.gz · Dernière modification : de cyrille
