Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def nchannel2rgb():
data = imgviz.data.arc2017()
np.random.seed(1234) # for PCA
nchannel_viz = imgviz.nchannel2rgb(data["res4"], dtype=np.float32)
H, W = data["rgb"].shape[:2]
nchannel_viz = imgviz.resize(nchannel_viz, height=H, width=W)
nchannel_viz = (nchannel_viz * 255).round().astype(np.uint8)
# -------------------------------------------------------------------------
plt.figure(dpi=200)
plt.subplot(121)
plt.title("rgb")
plt.imshow(data["rgb"])
plt.axis("off")
plt.subplot(122)
plt.title("res4 (colorized)")
plt.imshow(nchannel_viz)
plt.axis("off")
if args.fps is None:
args.fps = fps_src
writer = imageio.get_writer(output_file, fps=args.fps * args.speed)
scale = 1. * args.fps / fps_src
j = -1
for i in tqdm.trange(reader.get_length()):
elapsed_time = i * 1. / meta['fps']
if elapsed_time < args.start:
continue
frame = reader.get_data(i)
if width is not None and height is not None:
frame = imgviz.resize(
frame, height=height, width=width, interpolation='linear'
)
j_detail = i * scale
if int(round(j_detail)) != j:
writer.append_data(frame)
j = int(round(j_detail))
if args.duration:
duration = elapsed_time - args.start
if duration >= args.duration:
break
reader.close()
def resize():
data = imgviz.data.arc2017()
rgb = data["rgb"]
H, W = rgb.shape[:2]
rgb_resized = imgviz.resize(rgb, height=0.1)
# -------------------------------------------------------------------------
plt.figure(dpi=200)
plt.subplot(121)
plt.title("rgb:\n{}".format(rgb.shape))
plt.imshow(rgb)
plt.axis("off")
plt.subplot(122)
plt.title("rgb_resized:\n{}".format(rgb_resized.shape))
plt.imshow(rgb_resized)
plt.axis("off")
img = imgviz.io.pyplot_to_numpy()