LLNL / LEAP

comprehensive library of 3D transmission Computed Tomography (CT) algorithms with Python and C++ APIs, a PyQt GUI, and fully integrated with PyTorch
https://leapct.readthedocs.io
MIT License
101 stars 10 forks source link

Error for Simulation of projection and reconstruction for 2D fanbeam CT #103

Closed GreameLee closed 2 days ago

GreameLee commented 1 week ago

Hello, Dr.Kyle, I am Graeme, a PhD student focus on CT reconstruction problem. Recently I do a simulation about AAPM dataset. But weirdly, LEAP seems have a problem about it. I have preprocessed the dataset and the image have been saved as the "subtal1" in the mat file(I will attached it to this post). It is an image size of [256,256]. During using FBP and iterative method to do reconstruction. The FBP results looks good but the iterative reconstruction results does not make any sense.( P.s. The iterative method such as ASD-POCS, is follows after the FBP) I also attached the code. You can try this code on your dataset. By the way, I also attached another data which works good for this code. I will appreciate it if you can spend time on it and find the problem.

Here is the link to everything: https://drive.google.com/drive/folders/1gEriXubOBcpjKonnRVWP0Nu6dmJd60Nr?usp=sharing

kylechampley commented 1 week ago

Thanks for sending the code; I was able to reproduce the issue. I can fix the issue with two changes. First, add this line

f = np.ascontiguousarray(f, dtype=np.float32)

after the line that says

f = 255*img[None,:,:].astype(np.float32)

Also, I recommend you change the filter.append line to this:

filters.append(TV(leapct, delta=100.0/20.0))
GreameLee commented 1 week ago

Thanks for your replying and it works for me too. But I am trying to figure out why this works out. Can you explain why?

kylechampley commented 1 week ago

Numpy and pytorch can store data in non-contiguous ways which is fine if used within python because it knows how to handle this. LEAP requires that the data be contiguous. If you were using a numpy array, LEAP would have returned an error, but LEAP was not checking whether the torch tensors were contiguous.

I just pushed some changes to the champley_dev branch that includes a check that the data be contiguous. You can check this out now and use it, otherwise this feature will be included in the next LEAP release.

Regardless, sorry for the trouble.

kylechampley commented 2 days ago

I'm going to close this issue, but feel free to reopen it if you have more questions.