I am trying to compute 2D DCT (Discrete COsine Transform) on an tomographic image with tensorflow (in order to use it in a optimisation problem later) but doing 2D DCT once doesn't give me good results. I have to do it twice to get a sinogram. good sinogram
My code is the following
import tensorflow as tf
import skimage.io as skio
import numpy as np
import h5py
img_data = h5py.File('LoDoPaB-CT_dataset/ground_truth_test/ground_truth_test_000.hdf5', 'r')
print(list(img_data.keys()))
img_dset = img_data['data']
image = img_dset[20,:,:]
image = image.astype(np.float32) / image.max()
# Convert the image to a TensorFlow tensor
image_tensor = tf.constant(image)
NUM_ANGLES = 100
theta = np.linspace(5., 180., NUM_ANGLES, endpoint=False) # CHECK CHOICE OF THE ANGLES
# Reshape the image tensor to add a batch dimension
image_tensor_batched = tf.expand_dims(image_tensor, axis=0)
image_tensor_batched = tf.expand_dims(image_tensor_batched, axis=0)
def dct_2d(feature_map, norm=None ):
X1 = tf.signal.dct(feature_map, type=2, norm=norm)
X1_t = tf.transpose(X1, perm=[0, 1, 3, 2])
X2 = tf.signal.dct(X1_t, type=2, norm=norm)
X2_t = tf.transpose(X2, perm=[0, 1, 3, 2])
return X2_t
dct_tensor = dct_2d(image_tensor_batched)
# Remove the batch dimension and convert the result to a NumPy array
dct_array = tf.squeeze(dct_tensor)
with tf.compat.v1.Session() as sess:
array = sess.run(dct_array)
skio.imshow(radon(array, theta=theta, circle=False), cmap='gray')