-
-
Save jochemstoel/4288102efe756e2344d3829f892d2023 to your computer and use it in GitHub Desktop.
Tensorflow Crop to bounded box and save output image file
This file contains hidden or 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