Use `tf.image.resize_image_with_crop_or_pad` to resize numpy array

Use `tf.image.resize_image_with_crop_or_pad` to resize numpy array

Content Index :

Use `tf.image.resize_image_with_crop_or_pad` to resize numpy array
Tag : python , By : Naveen
Date : November 24 2020, 03:41 PM

will be helpful for those in need I want to use tf.image.resize_image_with_crop_or_pad on a Numpy array of shape (100,100,2) to get it cropped or padded to a target shape (h,w,2).
img = resize_image_with_crop_or_pad(img_tensor, target_height, target_width)
with tf.Session as sess:
    img_output = sess.run(img)
img_input = np.expand_dims(img_input, 0)
img_tensor = tf.convert_to_tensor(img_input)

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

(Python--numpy) how to resize and slice an numpy array with out a loop?

Tag : python , By : barefootChild
Date : March 29 2020, 07:55 AM
To fix this issue Yes you can use indexing with steps (in your example step would be 2):
import numpy as np

a = np.array([[1,2,3,4], [5,6,7,8], [9,8,7,6], [5,4,3,2]])
a[::2, ::2]
array([[1, 3],
       [9, 7]])

I am trying to convert a numpy array to PIL.Image. But it is giving black images. The numpy array is returned by pyramid

Tag : python , By : Simon Capewell
Date : March 29 2020, 07:55 AM
hop of those help? Check the values in pyr. Maybe they are values between 0 and `, while your RGB image is expected to be with values between 0 and 255.

How to resize N-d numpy image?

Tag : python , By : Ben
Date : November 11 2020, 03:01 PM
seems to work fine Reshape to split each axes into one more axis each of length 2, giving us a 6D array and then get the mean along those latter ones (axes : 1,3,5) -
m,n,r = a.shape
out = a.reshape(m//2,2,n//2,2,r//2,2).mean((1,3,5))
def shrink(a, S=2): # S : shrink factor
    new_shp = np.vstack((np.array(a.shape)//S,[S]*a.ndim)).ravel('F')
    return a.reshape(new_shp).mean(tuple(1+2*np.arange(a.ndim)))
In [407]: a
array([[[1, 5, 8, 2],
        [5, 6, 4, 0],
        [8, 5, 5, 5],
        [1, 0, 0, 0]],

       [[0, 0, 7, 6],
        [3, 5, 4, 3],
        [4, 5, 1, 3],
        [6, 7, 4, 0]]])

In [408]: a[:2,:2,:2].mean()
Out[408]: 3.125

In [409]: a[:2,:2,2:4].mean()
Out[409]: 4.25

In [410]: a[:2,2:4,:2].mean()
Out[410]: 4.5

In [411]: a[:2,2:4,2:4].mean()
Out[411]: 2.25

In [412]: shrink(a, S=2)
array([[[ 3.125,  4.25 ],
        [ 4.5  ,  2.25 ]]])

Numpy Resize/Rescale Image

Tag : python , By : Anand
Date : March 29 2020, 07:55 AM
should help you out Yeah, you can install opencv (this is a library used for image processing, and computer vision), and use the cv2.resize function. And for instance use:
import cv2
import numpy as np

img = cv2.imread('your_image.jpg')
res = cv2.resize(img, dsize=(54, 140), interpolation=cv2.INTER_CUBIC)

Tensorflow tf.image.resize_image_with_crop_or_pad For 3D Images

Tag : python , By : Ben Humphrys
Date : March 29 2020, 07:55 AM
it should still fix some issue i think your best bet is tf.pad, below code was not tested.
target_z = 170
# x is shape of (166, 256, 256)
zp = 170-x.get_shape().as_list()[0]
# what if zp is negative ?
paddings = tf.constant([[0, zp], [0, 0], [0,0]])
tf.pad(x, paddings, "CONSTANT") 
Related Posts Related QUESTIONS :
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Pandas giving IndexError on one dataframe but not on another similar dataframe
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • a thread python with 'while' got another thread never start
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com