imgproc.py
Go to the documentation of this file.
1 """
2 Copyright (c) 2019-present NAVER Corp.
3 MIT License
4 """
5 
6 # -*- coding: utf-8 -*-
7 
8 from __future__ import division
9 
10 import cv2
11 import numpy as np
12 
13 
15  in_img, mean=(
16  0.485, 0.456, 0.406), variance=(
17  0.229, 0.224, 0.225)):
18  # should be RGB order
19  img = in_img.copy().astype(np.float32)
20 
21  img -= np.array([mean[0] * 255.0, mean[1] * 255.0,
22  mean[2] * 255.0], dtype=np.float32)
23  img /= np.array([variance[0] * 255.0, variance[1] * 255.0,
24  variance[2] * 255.0], dtype=np.float32)
25  return img
26 
27 
29  in_img, mean=(
30  0.485, 0.456, 0.406), variance=(
31  0.229, 0.224, 0.225)):
32  # should be RGB order
33  img = in_img.copy()
34  img *= variance
35  img += mean
36  img *= 255.0
37  img = np.clip(img, 0, 255).astype(np.uint8)
38  return img
39 
40 
41 def resize_aspect_ratio(img, square_size, interpolation, mag_ratio=1):
42  height, width, channel = img.shape
43 
44  # magnify image size
45  target_size = mag_ratio * max(height, width)
46 
47  # set original image size
48  if target_size > square_size:
49  target_size = square_size
50 
51  ratio = target_size / max(height, width)
52 
53  target_h, target_w = int(height * ratio), int(width * ratio)
54  proc = cv2.resize(img, (target_w, target_h), interpolation=interpolation)
55 
56  # make canvas and paste image
57  target_h32, target_w32 = target_h, target_w
58  if target_h % 32 != 0:
59  target_h32 = target_h + (32 - target_h % 32)
60  if target_w % 32 != 0:
61  target_w32 = target_w + (32 - target_w % 32)
62  resized = np.zeros((target_h32, target_w32, channel), dtype=np.float32)
63  resized[0:target_h, 0:target_w, :] = proc
64  target_h, target_w = target_h32, target_w32
65 
66  size_heatmap = (int(target_w / 2), int(target_h / 2))
67 
68  return resized, ratio, size_heatmap
69 
70 
71 def cvt2HeatmapImg(img):
72  img = (np.clip(img, 0, 1) * 255).astype(np.uint8)
73  img = cv2.applyColorMap(img, cv2.COLORMAP_JET)
74  return img
ssd_train_dataset.int
int
Definition: ssd_train_dataset.py:175
node_scripts.craft.imgproc.denormalizeMeanVariance
def denormalizeMeanVariance(in_img, mean=(0.485, 0.456, 0.406), variance=(0.229, 0.224, 0.225))
Definition: imgproc.py:28
node_scripts.craft.imgproc.cvt2HeatmapImg
def cvt2HeatmapImg(img)
Definition: imgproc.py:71
node_scripts.craft.imgproc.resize_aspect_ratio
def resize_aspect_ratio(img, square_size, interpolation, mag_ratio=1)
Definition: imgproc.py:41
node_scripts.craft.imgproc.normalizeMeanVariance
def normalizeMeanVariance(in_img, mean=(0.485, 0.456, 0.406), variance=(0.229, 0.224, 0.225))
Definition: imgproc.py:14


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Fri May 16 2025 03:11:17