简体   繁体   中英

Nonuniform sampling for 2D image in Python

I have a 2D image that can be represented as a Numpy array in Python. I need to downsample this image in a way that downsampling happens more at the sides and less at the center. To be more specific, let's say downsampling with rate 2 at the center, 4 at the borders, and something in between (relative to the distance to the center) on other points. In other words, I am looking for the nonUniformDownsample function in the code below:

img = cv2.imread("flower.jpg") 
img_focused = nonUniformDownsample(image=img, centerVal=2, borderVal=4)

I'm not certain I understand your question/goal, but as will commented scipy.interpolate.griddata should work. You could use something like this:

X,Y = np.meshgrid(np.linspace(-1,1,100), np.linspace(-1,1,100))
A = np.sin(9.5*pi*X) + np.sin(9.5*np.pi*Y)

Here A looks like this:

在此处输入图片说明

n = 50
X_, Y_ = np.meshgrid(np.linspace(-1,1,n), np.linspace(-1,1,n))
X_ = (3*X_**3 + X_) / 4
Y_ = (3*Y_**3 + Y_) / 4

x = np.dstack((X,Y)).reshape((100*100, 2))
xi = np.dstack((X_,Y_)).reshape((n*n, 2))
A_ = griddata(x, A.flat, xi, method='cubic')

And A_ looks like this:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM