8.1.2.8. blueoil.pre_processor

8.1.2.8.1. Module Contents

8.1.2.8.1.1. Classes

PerImageLinearQuantize

Linear quantize per image.

PerImageStandardization

Standardization per image.

Resize

Resize image.

ResizeWithGtBoxes

Resize image with gt boxes.

ResizeWithMask

Resize image and mask.

ResizeWithJoints

Resize image and joints.

DivideBy255

Divide image by 255.

LetterBoxes

Darknet’s letter boxes

JointsToGaussianHeatmap

Convert joints to gaussian heatmap which can be learned by networks.

8.1.2.8.1.2. Functions

resize(image, size=[256, 256], resample=’NEAREST’)

Resize an image.

square(image, gt_boxes, fill=127.5)

Square an image.

resize_with_gt_boxes(image, gt_boxes, size=(256, 256), resample=’NEAREST’)

Resize an image and gt_boxes.

resize_keep_ratio_with_gt_boxes(image, gt_boxes, size=(256, 256), resample=’NEAREST’)

Resize keeping ratio an image and gt_boxes.

resize_with_joints(image, joints, image_size, resample=’NEAREST’)

Resize image with joints to target image_size.

per_image_standardization(image)

Image standardization per image.

per_image_linear_quantize(image, bit)

Linear quantize per image.

_linear_quantize(x, bit, value_min, value_max)

joints_to_gaussian_heatmap(joints, image_size, num_joints=17, stride=1, sigma=2)

Convert joints to gaussian heatmap which can be learned by networks.

blueoil.pre_processor.RESAMPLE_METHODS
blueoil.pre_processor.resize(image, size=[256, 256], resample='NEAREST')

Resize an image.

Parameters
  • image (np.ndarray) – an image numpy array.

  • size – [height, width]

  • resample (str) – A name of resampling filter

blueoil.pre_processor.square(image, gt_boxes, fill=127.5)

Square an image.

Parameters
  • image – An image numpy array.

  • gt_boxes – Python list ground truth boxes in the image. shape is [num_boxes, 5(x, y, width, height)].

  • fill – Fill blank by this number. (Default value = 127.5)

blueoil.pre_processor.resize_with_gt_boxes(image, gt_boxes, size=(256, 256), resample='NEAREST')

Resize an image and gt_boxes.

Parameters
  • image (np.ndarray) – An image numpy array.

  • gt_boxes (np.ndarray) – Ground truth boxes in the image. shape is [num_boxes, 5(x, y, width, height, class_id)].

  • size – [height, width]

  • resample (str) – A name of resampling filter

blueoil.pre_processor.resize_keep_ratio_with_gt_boxes(image, gt_boxes, size=(256, 256), resample='NEAREST')

Resize keeping ratio an image and gt_boxes.

Parameters
  • image (np.ndarray) – An image numpy array.

  • gt_boxes (list) – Python list ground truth boxes in the image. shape is [num_boxes, 5(x, y, width, height)].

  • size – [height, width]

  • resample (str) – A name of resampling filter

blueoil.pre_processor.resize_with_joints(image, joints, image_size, resample='NEAREST')

Resize image with joints to target image_size.

Parameters
  • image – a numpy array of shape (height, width, 3).

  • joints – a numpy array of shape (num_joints, 3).

  • image_size – a tuple, (new_height, new_width).

  • resample (str) – A name of resampling filter

Returns

a numpy array of shape (new_height, new_width, 3). new_joints: a numpy array of shape (num_joints, 3).

Return type

resized_image

blueoil.pre_processor.per_image_standardization(image)

Image standardization per image.

https://www.tensorflow.org/api_docs/python/image/image_adjustments#per_image_standardization

Parameters

image – An image numpy array.

blueoil.pre_processor.per_image_linear_quantize(image, bit)

Linear quantize per image.

\[\mathbf{Y} = \frac{\text{round}\big(\frac{\mathbf{X}}{max\_value} \cdot (2^{bit}-1)\big)}{2^{bit}-1} \cdot max\_value\]
Parameters
  • image – An image numpy array.

  • bit – Quantize bit.

blueoil.pre_processor._linear_quantize(x, bit, value_min, value_max)
blueoil.pre_processor.joints_to_gaussian_heatmap(joints, image_size, num_joints=17, stride=1, sigma=2)

Convert joints to gaussian heatmap which can be learned by networks.

References

https://github.com/Microsoft/human-pose-estimation.pytorch

Parameters
  • joints (np.ndarray) – a numpy array of shape (num_joints).

  • image_size (tuple) – a tuple, (height, width).

  • num_joints (int) – int. (Default value = 17)

  • stride (int) – int, stride = image_height / heatmap_height. (Default value = 1)

  • sigma (int) – int, used to compute gaussian heatmap. (Default value = 2)

Returns

a numpy array of shape (height, width, num_joints).

Return type

heatmap

class blueoil.pre_processor.PerImageLinearQuantize(bit)

Bases: blueoil.data_processor.Processor

Linear quantize per image.

Use per_image_linear_quantize() inside.

Parameters

bit – Quantize bit.

__call__(self, image, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.PerImageStandardization

Bases: blueoil.data_processor.Processor

Standardization per image.

Use per_image_standardization() inside.

__call__(self, image, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.Resize(size, resample='NEAREST')

Bases: blueoil.data_processor.Processor

Resize image.

Use resize() inside.

Parameters
  • size – Target size.

  • resample (str) – A name of resampling filter

__call__(self, image, mask=None, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.ResizeWithGtBoxes(size, resample='NEAREST')

Bases: blueoil.data_processor.Processor

Resize image with gt boxes.

Use resize_with_gt_boxes() inside.

Parameters
  • size – Target size.

  • resample (str) – A name of resampling filter

__call__(self, image, gt_boxes=None, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.ResizeWithMask(size, resample='NEAREST')

Bases: blueoil.data_processor.Processor

Resize image and mask.

Use resize() inside.

Parameters
  • size – Target size.

  • resample (str) – A name of resampling filter

__call__(self, image, mask=None, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.ResizeWithJoints(image_size, resample='NEAREST')

Bases: blueoil.data_processor.Processor

Resize image and joints.

Use resize_with_joints() inside.

Parameters
  • image_size – Target size.

  • resample (str) – A name of resampling filter

__call__(self, image, joints=None, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.DivideBy255

Bases: blueoil.data_processor.Processor

Divide image by 255.

__call__(self, image, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.LetterBoxes(size, resample='NEAREST')

Bases: blueoil.data_processor.Processor

Darknet’s letter boxes

Use resize_keep_ratio_with_gt_boxes() inside.

Parameters
  • size – Target size.

  • resample (str) – A name of resampling filter

__call__(self, image, gt_boxes=None, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.

class blueoil.pre_processor.JointsToGaussianHeatmap(image_size, num_joints=17, stride=1, sigma=3)

Bases: blueoil.data_processor.Processor

Convert joints to gaussian heatmap which can be learned by networks.

Use joints_to_gaussian_heatmap() inside.

Parameters
  • image_size (tuple) – a tuple, (height, width).

  • num_joints (int) – int.

  • stride (int) – int, stride = image_height / heatmap_height.

  • sigma (int) – int, used to compute gaussian heatmap.

Returns

Return type

dict

__call__(self, joints=None, **kwargs)

Call processor method for each a element of data.

Return image and labels etc.