-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproject.py
More file actions
33 lines (27 loc) · 1.72 KB
/
project.py
File metadata and controls
33 lines (27 loc) · 1.72 KB
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
import argparse
from settings import Settings
from sampler import Sampler
from PIL import Image
from projections.map import projections_map
parser = argparse.ArgumentParser()
parser.add_argument('image', type=str, help='Input image file')
parser.add_argument('--in-projection', type=str, default='auto', help=f'Input image projection. One of {projections_map.keys()}')
parser.add_argument('--out', type=str, default='out.jpg', help='Output file name')
parser.add_argument('--out-projection', type=str, help=f'Output image projection. One of {projections_map.keys()}')
parser.add_argument('--width', type=int, help='Width of output image, in pixels')
parser.add_argument('--height', type=int, help='Height of output image, in pixels')
parser.add_argument('--rotation', type=str, help='Rotate by given angles (<x>,<y>,<z> in degrees)')
parser.add_argument('--samples', type=int, default=1, help='Take NxN samples per pixel. Caution: Slow.')
parser.add_argument('--hemi-fov-x', type=int, default=180, help='Horizontal field of view (in degrees) of hemispherical projection')
parser.add_argument('--hemi-fov-y', type=int, default=180, help='Vertical field of view (in degrees) of hemispherical projection')
args = parser.parse_args()
input_image = Image.open(args.image).convert('RGB')
settings = Settings(args, input_image)
sampler = Sampler(args, settings, lambda in_x, in_y: input_image.getpixel((in_x, in_y)))
output_image = Image.new('RGB', (settings.out_width, settings.out_height), 'black')
# Render image
for out_y in range(settings.out_height):
for out_x in range(settings.out_width):
sample = sampler.get_supersample(out_x, out_y, args.samples)
output_image.putpixel((out_x, out_y), sample)
output_image.save(args.out, quality=90)