下面的代码是我的模型的一部分,正在尝试进行线性插值,类似于numpy.interp()。在我的模型中,t的形状为(64,64)。x的形状为(91,)。y的形状为(91,)。
def tf_interp(b, x, y):
xaxis_pad = tf.concat([[tf.minimum(b, tf.gather(x, 0))], x, [tf.maximum(b, tf.gather(x, height_sino - 1))]],
axis=0)
yaxis_pad = tf.concat([[0.0], y, [0.0]], axis=0)
cmp = tf.cast(b > xaxis_pad, dtype=tf.float32)
diff = cmp[1:] - cmp[:-1]
idx = tf.argmin(diff)
# Interpolate
alpha = (b - xaxis_pad[idx]) / (xaxis_pad[idx + 1] - xaxis_pad[idx])
res = alpha * yaxis_pad[idx + 1] + (1 - alpha) * yaxis_pad[idx]
#def f1(): return 0.0
#def f2(): return alpha * yaxis_pad[idx + 1] + (1 - alpha) * …Run Code Online (Sandbox Code Playgroud) 这可能是一个简单的问题。我只是想对图像进行氡变换并使用 TensorFlow 中的函数保存它。但结果不对。我知道我可以使用 plt.imsave() 来正确保存图像,但我想知道如何在 TensorFlow 中做到这一点。
我是 TensorFlow 的新手,感谢您的帮助。
这是shepp-logan.jpg我使用的图像。它是大小为 64*64 的灰度图像
这是我的代码。
from skimage.transform import radon,iradon
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
sess = tf.Session()
img = plt.imread('shepp-logan.jpg')
theta = np.linspace(0., 180., max(img.shape), endpoint=False)
sinogram = radon(img, theta=theta, circle=True)
sinogram = tf.cast(sinogram, tf.uint8)
sinogram = tf.expand_dims(sinogram, -1)
sinogram = tf.image.encode_jpeg(sinogram, quality=100, format='grayscale')
writer = tf.write_file('test_sinogram.jpg', sinogram)
sess.run(writer)
Run Code Online (Sandbox Code Playgroud)