Forked from SiddharthSudhakar/Crop_To_Bounded_Box
Created
September 18, 2017 13:27
-
-
Save kodekracker/8d9eb1fa782fbbd23fc28f15d1be2231 to your computer and use it in GitHub Desktop.
Tensorflow Crop to bounded box and save output image file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
# Import the image | |
image = tf.image.decode_png(tf.read_file("./data/Input_image.png"), channels=1) | |
## Set the variable values here | |
# Offset variables values | |
offset_height= 20 | |
offset_width = 20 | |
# Target variables values | |
target_height = 20 | |
target_width = 20 | |
# Begin the session | |
session = tf.InteractiveSession() | |
print(session.run(image)) | |
# Crop the image as per the parameters | |
cropped_image_tensor = tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width) | |
output_image = tf.image.encode_png(cropped_image_tensor) | |
# Create a constant as filename | |
file_name = tf.constant('./data/Ouput_image.png') | |
file = tf.write_file(file_name, output_image) | |
# print(session.run(file)) | |
print("Image Saved!") | |
session.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, How do we save a batch of images? does tf.write_file work?