forked from cosmas-heiss/JunoCamRawImageProcessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.py
More file actions
58 lines (43 loc) · 1.68 KB
/
Example1.py
File metadata and controls
58 lines (43 loc) · 1.68 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
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
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import json
from PIL import Image
from mayavi import mlab
import cv2
from Util import *
from Framelets import *
from JitterCorrection import *
from Vis3D import *
from ColorCorrection import *
image = 'JNCE_2019149_20C00028_V01-raw.png'
im_info = 'JNCE_2019149_20C00028_V01.json'
with open(im_info, 'rb') as json_file:
im_info_dir = json.load(json_file)
img = Image.open(image)
im_ar = np.array(img)
s1, s2 = im_ar.shape
start_time = im_info_dir["START_TIME"]
frame_delay = float(im_info_dir["INTERFRAME_DELAY"].split()[0])+0.001
start_correction, frame_delay = correct_image_start_time_and_frame_delay(im_ar, start_time, frame_delay)
framelets = generate_framelets(revert_square_root_encoding(im_ar), start_time, start_correction, frame_delay)
cam_pos, cam_orient = get_junocam_jupiter_rel_pos_orient(start_time, start_correction + 17 * frame_delay)
y, x = np.mgrid[-256:256,-256:256]
x += 260
y += 95
rays = np.concatenate([x[...,None], y[...,None], np.ones((512,512,1))*fl[0]], axis=-1)
rays = rays.dot(cam_orient)
surface_raster, _ = project_onto_jupiter_surf(cam_pos, rays)
colors = np.zeros((512,512,3))
color_counts = np.zeros((512,512,3))
for k,framelet in enumerate(framelets):
print('Processing framelet {} of {}..'.format(k+1, len(framelets)))
col = framelet.color
brightnesses, valid_map = framelet.get_pixel_val_at_surf_point(surface_raster)
colors[...,2-col] += brightnesses
color_counts[...,2-col] += valid_map
colors /= np.maximum(color_counts, 1)
colors *= 255 / np.max(colors)
colors = colors.astype(np.uint8)
new_img = Image.fromarray(colors)
new_img.save("Example1.png")