Link Search Menu Expand Document

CropAndResize


tensorflow C++ API

tensorflow::ops::CropAndResize

Extracts crops from the input image tensor and bilinearly resizes them (possibly with aspect ratio change) to a common output size specified bycrop_size.


Summary

This is more general than thecrop_to_bounding_boxop which extracts a fixed size slice from the input image and does not allow resizing or aspect ratio change.

Returns a tensor withcropsfrom the inputimageat positions defined at the bounding box locations inboxes. The cropped boxes are all resized (with bilinear interpolation) to a fixedsize = [crop_height, crop_width]. The result is a 4-D tensor[num_boxes, crop_height, crop_width, depth].

Arguments:

  • scope: A Scope object
  • image: A 4-D tensor of shape[batch, image_height, image_width, depth]. Bothimage_heightandimage_widthneed to be positive.
  • boxes: A 2-D tensor of shape[num_boxes, 4]. Thei-th row of the tensor specifies the coordinates of a box in the box_ind[i]image and is specified in normalized coordinates[y1, x1, y2, x2]. A normalized coordinate value of yis mapped to the image coordinate aty * (image_height - 1), so as the[0, 1]interval of normalized image height is mapped to[0, image_height - 1]in image height coordinates. We do allowy1>y2, in which case the sampled crop is an up-down flipped version of the original image. The width dimension is treated similarly. Normalized coordinates outside the [0, 1]range are allowed, in which case we useextrapolation_valueto extrapolate the input image values.
  • box_ind: A 1-D tensor of shap[num_boxes]with int32 values in[0, batch). The value ofbox_ind[i]specifies the image that thei-th box refers to.crop_size: A 1-D tensor of 2 elements,size = [crop_height, crop_width].All cropped image patches are resized to this size. The aspect ratio of the image content is not preserved. Bothcrop_heightandcrop_widthneed to be positive.
  • crop_size: A 1-D tensor of 2 elements, size = [crop_height, crop_width]. All cropped image patches are resized to this size. The aspect ratio of the image content is not preserved. Both crop_height and crop_width need to be positive.

Optional attributes (seeAttrs):

  • method: A string specifying the interpolation method. Only ‘bilinear’ is supported for now.
  • extrapolation_value: Value used for extrapolation, when applicable.

Returns:

  • Output: A 4-D tensor of shape[num_boxes, crop_height, crop_width, depth].

Constructor

  • CropAndResize(const ::tensorflow::Scope & scope, ::tensorflow::Input image, ::tensorflow::Input boxes, ::tensorflow::Input box_ind, ::tensorflow::Input crop_size, const CropAndResize::Attrs & attrs) .

Public attributes

  • tensorflow::Output crops.

CropAndResize block

Source link : https://github.com/EXPNUNI/enuSpaceTensorflow/blob/master/enuSpaceTensorflow/tf_image_ops.cpp

Argument:

  • Scope scope : A Scope object (A scope is generated automatically each page. A scope is not connected.)
  • image : connect Input node.
  • boxes : connect Input node or input float value.
  • box_ind : connect Input node or input int32 value.
  • crop_size : connect Input node or input int32 value.
  • CropAndResize::Attrs attrs : input attrs. ex) method_ = “bilinear”;extrapolation_value_ = 0.0f;

Return:

  • Output crops: Output object of CropAndResize class object.

Result:

  • std::vector(Tensor) product_result : Returned object of executed result by calling session.

Using Method