Skip to main content
added 12 characters in body
Source Link
sebrockm
  • 6.1k
  • 3
  • 22
  • 45

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

def crop_center(image):
    h, w = image.shape[-3], image.shape[-2]
    if h > w:
        cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
    else:
        cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)
    return tf.image.resize_images(cropped_image, (100, 100))

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

def crop_center(image):
    h, w = image.shape[-3], image.shape[-2]
    if h > w:
        cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
    else:
        cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)
    return tf.image.resize_images(cropped_image)

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

def crop_center(image):
    h, w = image.shape[-3], image.shape[-2]
    if h > w:
        cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
    else:
        cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)
    return tf.image.resize_images(cropped_image, (100, 100))
added 51 characters in body
Source Link
sebrockm
  • 6.1k
  • 3
  • 22
  • 45

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

def crop_center(image):
    h, w = image.shape[-3], image.shape[-2]
    if h > w:
        cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
    else:
        cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)
    return tf.image.resize_images(cropped_image)

cropped_image will be 50 x 50 in your example, then resize it.

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

h, w = image.shape[-3], image.shape[-2]
if h > w:
    cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
else:
    cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)

cropped_image will be 50 x 50 in your example, then resize it.

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

def crop_center(image):
    h, w = image.shape[-3], image.shape[-2]
    if h > w:
        cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
    else:
        cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)
    return tf.image.resize_images(cropped_image)
added 51 characters in body
Source Link
sebrockm
  • 6.1k
  • 3
  • 22
  • 45

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

h, w = image.shape[-3], image.shape[-2]
if h > w:
    cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
else:
    cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)

cropped_image will be 50 x 50 in your example, then resize it.

Sounds like crop_to_bounding_box is doing what you need:

h, w = image.shape[-3], image.shape[-2]
if h > w:
    cropped_image = crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
else:
    cropped_image = crop_to_bounding_box(image, 0, (w - h) // 2, h, h)

cropped_image will be 50 x 50 in your example, then resize it.

Sounds like crop_to_bounding_box is doing what you need:

import tensorflow as tf

h, w = image.shape[-3], image.shape[-2]
if h > w:
    cropped_image = tf.image.crop_to_bounding_box(image, (h - w) // 2, 0, w, w)
else:
    cropped_image = tf.image.crop_to_bounding_box(image, 0, (w - h) // 2, h, h)

cropped_image will be 50 x 50 in your example, then resize it.

added 104 characters in body
Source Link
sebrockm
  • 6.1k
  • 3
  • 22
  • 45
Loading
Source Link
sebrockm
  • 6.1k
  • 3
  • 22
  • 45
Loading