mirror of
https://github.com/graphdeco-inria/gaussian-splatting
synced 2025-04-28 01:51:38 +00:00
moved magick to PIL as even singlethreaded is 4x the speed in resizing that magick
This commit is contained in:
parent
414b553ef1
commit
7857f24260
41
convert.py
41
convert.py
@ -8,12 +8,16 @@
|
|||||||
#
|
#
|
||||||
# For inquiries contact george.drettakis@inria.fr
|
# For inquiries contact george.drettakis@inria.fr
|
||||||
#
|
#
|
||||||
|
# xvdp removed magick, it is 3x slower than single threaded PIL for resizing
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
# This Python script is based on the shell converter script provided in the MipNerF 360 repository.
|
# This Python script is based on the shell converter script provided in the MipNerF 360 repository.
|
||||||
parser = ArgumentParser("Colmap converter")
|
parser = ArgumentParser("Colmap converter")
|
||||||
parser.add_argument("--no_gpu", action='store_true')
|
parser.add_argument("--no_gpu", action='store_true')
|
||||||
@ -25,7 +29,7 @@ parser.add_argument("--resize", action="store_true")
|
|||||||
parser.add_argument("--magick_executable", default="", type=str)
|
parser.add_argument("--magick_executable", default="", type=str)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
colmap_command = '"{}"'.format(args.colmap_executable) if len(args.colmap_executable) > 0 else "colmap"
|
colmap_command = '"{}"'.format(args.colmap_executable) if len(args.colmap_executable) > 0 else "colmap"
|
||||||
magick_command = '"{}"'.format(args.magick_executable) if len(args.magick_executable) > 0 else "magick"
|
|
||||||
use_gpu = 1 if not args.no_gpu else 0
|
use_gpu = 1 if not args.no_gpu else 0
|
||||||
|
|
||||||
if not args.skip_matching:
|
if not args.skip_matching:
|
||||||
@ -87,38 +91,21 @@ for file in files:
|
|||||||
destination_file = os.path.join(args.source_path, "sparse", "0", file)
|
destination_file = os.path.join(args.source_path, "sparse", "0", file)
|
||||||
shutil.move(source_file, destination_file)
|
shutil.move(source_file, destination_file)
|
||||||
|
|
||||||
if(args.resize):
|
if args.resize:
|
||||||
print("Copying and resizing...")
|
print("Copying and resizing...")
|
||||||
|
|
||||||
# Resize images.
|
# Resize images.
|
||||||
os.makedirs(args.source_path + "/images_2", exist_ok=True)
|
for div in [2,4,8]:
|
||||||
os.makedirs(args.source_path + "/images_4", exist_ok=True)
|
os.makedirs(args.source_path + f"/images_{div}", exist_ok=True)
|
||||||
os.makedirs(args.source_path + "/images_8", exist_ok=True)
|
|
||||||
# Get the list of files in the source directory
|
# Get the list of files in the source directory
|
||||||
files = os.listdir(args.source_path + "/images")
|
files = os.listdir(args.source_path + "/images")
|
||||||
# Copy each file from the source directory to the destination directory
|
# Copy each file from the source directory to the destination directory
|
||||||
for file in files:
|
for j, file in enumerate(files):
|
||||||
source_file = os.path.join(args.source_path, "images", file)
|
source_file = os.path.join(args.source_path, "images", file)
|
||||||
|
im = Image.open(source_file)
|
||||||
destination_file = os.path.join(args.source_path, "images_2", file)
|
logging.info(f"processing image [{j}/{len(files)}] {source_file}")
|
||||||
shutil.copy2(source_file, destination_file)
|
for div in [2,4,8]:
|
||||||
exit_code = os.system(magick_command + " mogrify -resize 50% " + destination_file)
|
destination_file = os.path.join(args.source_path, f"images_{div}", file)
|
||||||
if exit_code != 0:
|
im.resize([round(i/div) for i in im.size], Image.BICUBIC).save(destination_file)
|
||||||
logging.error(f"50% resize failed with code {exit_code}. Exiting.")
|
|
||||||
exit(exit_code)
|
|
||||||
|
|
||||||
destination_file = os.path.join(args.source_path, "images_4", file)
|
|
||||||
shutil.copy2(source_file, destination_file)
|
|
||||||
exit_code = os.system(magick_command + " mogrify -resize 25% " + destination_file)
|
|
||||||
if exit_code != 0:
|
|
||||||
logging.error(f"25% resize failed with code {exit_code}. Exiting.")
|
|
||||||
exit(exit_code)
|
|
||||||
|
|
||||||
destination_file = os.path.join(args.source_path, "images_8", file)
|
|
||||||
shutil.copy2(source_file, destination_file)
|
|
||||||
exit_code = os.system(magick_command + " mogrify -resize 12.5% " + destination_file)
|
|
||||||
if exit_code != 0:
|
|
||||||
logging.error(f"12.5% resize failed with code {exit_code}. Exiting.")
|
|
||||||
exit(exit_code)
|
|
||||||
|
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
Loading…
Reference in New Issue
Block a user