Comments (26)
Also note that tomopy is not able to find center for this. its giving some strange value.
You suspect that the automatic center finding function is not working for you dataset, so use the manual finding center function.
from tomopy.
Tried this but no reconstruction was saved in the respective folder. Anything more is suppose to be done?
from tomopy.
Look in ./file_name
?
from tomopy.
Here is the folder.... its empty.
from tomopy.
Another issue here is center of rotation may be tilted along a line. so it is not really fixed for all slices.
from tomopy.
In the example you provided, you assign dpath to the literal string 'file_name'
not the variable file_name
. Look in the working directory of your jupyter notebook, not '/asap3/petra/[other paths]/recon_center
. Or fix your code to use the variable name instead of a string literal.
from tomopy.
I got you point. but that would not solve the issue which I mentioned earlier. "Another issue here is center of rotation may be tilted along a line. so it is not really fixed for all slices."
Is it possible for you to share your mail or discord or any other communication channel. Because the issue with tilted axis seems a bit complex but when it is fixed, it would give some amazing reconstruction.
from tomopy.
Manually find the center for 5 points along the volume (top, middles, bottom), then fit the centers to a line as a function of slice index. Use interpolation to estimate the centers for slices between the ones you manually found.
from tomopy.
No, there is no discord/chat group.
from tomopy.
I will make a google drive with some part data and share the ipynb file. May be you can spot a issue in finding the center and fitting the center. Actually manually doing it is not the most relevant option as I need to do the same for wide rage of samples and wide range of scans.
from tomopy.
Here is the drive link.
https://drive.google.com/drive/folders/1qvPyHyhwxzFQYujDmVutBhl2H42tqb5_?usp=sharing
Data seems bit big, so i have croped it and generated npy array. Please request you to have a look.
Thanks in advance :)
from tomopy.
Any updates?
from tomopy.
Sorry, but I don't have the bandwidth to debug your entire reconstruction workflow. If you have a small, specific, self-contained code example of something that is not working, I can take a look.
Also, we have multiple different algorithms for automatically estimating the rotation center. Perhaps, one of the others works better for your dataset.
from tomopy.
I can help Daniel here. Note that the sinogram is 360-degree sinogram, so to use find_center_vo we have to pass a half of the sinogram.
import tomopy
import numpy as np
from PIL import Image
import multiprocessing as mp
import algotom.prep.correction as corr
def load_image(file_path):
try:
mat = np.asarray(Image.open(file_path), dtype=np.float32)
except IOError:
print(("No such file or directory: {}").format(file_path))
raise
if len(mat.shape) > 2:
axis_m = np.argmin(mat.shape)
mat = np.mean(mat, axis=axis_m)
return mat
def save_image(file_path, mat):
image = Image.fromarray(mat)
try:
image.save(file_path)
except IOError:
print(("Couldn't write to file {}").format(file_path))
raise
return file_path
if __name__ == '__main__':
print("Start......")
# Load data, note that the projections are in the range of 0-360 degree
proj = np.load("E:/Tomo_data/tomo/proj.npy")
flat = np.mean(np.load("E:/Tomo_data/tomo/flat.npy"), axis=0)
dark = np.mean(np.load("E:/Tomo_data/tomo/dark.npy"), axis=0)
ncore = mp.cpu_count() - 1
(depth, height, width) = proj.shape
angles = np.linspace(0.0, 360.0, depth) * np.pi / 180.0
idx = 30
# Before tilted correction
sinogram = (proj[:, idx] - dark[idx]) / (flat[idx] - dark[idx])
# Find center of rotation:
# Reduce number of projections as 3600 projections are more than enough
# for finding the center. Note that we need to pass 180-degree sinogram
# for the finding method.
center = tomopy.find_center_vo(
np.expand_dims(sinogram[0:depth // 2 + 1: 5], 1), ncore=ncore)
sinogram = -np.log(sinogram)
rec_image = tomopy.recon(np.expand_dims(sinogram, 1), angles, center=center, algorithm="gridrec", ncore=ncore)
rec_image = tomopy.circ_mask(rec_image, axis=0, ratio=1.0)[0]
save_image("E:/Tomo_data/tomo/rec_image_before.tif", rec_image)
# Find center at different height for calculating the tilt angle
list_center = []
for i in range(0, height, height // 2 - 1):
print("Find center at slice {}".format(i))
sinogram = (proj[0:depth // 2 + 1:5, i] - dark[i]) / (flat[i] - dark[i])
center = tomopy.find_center_vo(np.expand_dims(sinogram, 1), ncore=ncore)
print("Center is {}".format(center))
list_center.append([i, center])
list_center = np.asarray(list_center)
# Find the tilt angle using linear fit
tilt_angle = -np.rad2deg(np.arctan(np.polyfit(list_center[:, 0], list_center[:, 1], 1)[0]))
print("Tilt angle: {}".format(tilt_angle))
# tilt_angle = -0.5729386976835696
# Generate tilted sinogram using algotom
sino_tilted = corr.generate_tilted_sinogram(proj, idx, tilt_angle)
flat_line = corr.generate_tilted_profile_line(flat, idx, tilt_angle)
dark_line = corr.generate_tilted_profile_line(dark, idx, tilt_angle)
sinogram = corr.flat_field_correction(sino_tilted, flat_line, dark_line)
center = tomopy.find_center_vo(np.expand_dims(sinogram, 1), ncore=ncore)
print("Center after tilt correction is {}".format(center))
# save_image("E:/Tomo_data/tomo/sino_image.tif", sinogram)
sinogram = -np.log(sinogram)
rec_image = tomopy.recon(np.expand_dims(sinogram, 1), angles, center=center, algorithm="gridrec", ncore=ncore)
rec_image = tomopy.circ_mask(rec_image, axis=0, ratio=1.0)[0]
save_image("E:/Tomo_data/tomo/rec_image_after.tif", rec_image)
print("Done!")
This is just for the data you sent. To process original datasets (hdf format) in automated fashion you may want to refer an example here.
from tomopy.
Thank You @nghia-vo for you time and really thankfull and appricaite that you gave you precious time to fix my problem. Also Thanks @carterbox for your help.
@nghia-vo I don't have data in hdf format. My data is 3600 projecting tiff's and its huge (aroung 40 GB) do you have a way that I can share that.
from tomopy.
@nghia-vo When I tried it with my data, this is what happens.
from tomopy.
You're welcome. Convert tifs to hdf make it easy to process sinogram-by-sinogram and allow to process large data using a small RAM computer. Check examples here and here to know how.
From reconstructed images, look like the tilt angle is incorrectly determined. What value did you get? Did you resize the data you sent (npy) compared to tif images? What is the original size of tif image (height x width)?. If you resize your data, you have to recalculate the tilt angle. Send me sinograms at the top, middle, and bottom to double check.
from tomopy.
This is what I got.... it finds center as 632, 632 and 634. But after tited correction its says 658.
from tomopy.
Try by reversing the sign of the angle:
tilt_angle = -tilt_angle
from tomopy.
Tried it... still the same.
from tomopy.
Hm, could you upload the sinograms before and after corrections to the same google drive above? I'll have a look.
from tomopy.
Hi,
I am also trying the same with other sample which does'nt seem to work at all. I have shared npy array of that sample in my drive folder name 'al_sample'. I tried your code loading with this sample but does not give any reconstruction.
Also about your previous coment about sharing sinograms, I have shared the sinogrambefore and sinogramafter numpy array in the drive link above in tomo folder.
Thank You.
from tomopy.
I don't know what between your codes can cause the problem, but I got good results using the sinogram you sent:
Output:
Start......
Center of rotation before 632.25
Center of rotation after 633.0
Done!
def load_image(file_path):
try:
mat = np.asarray(Image.open(file_path), dtype=np.float32)
except IOError:
print(("No such file or directory: {}").format(file_path))
raise
if len(mat.shape) > 2:
axis_m = np.argmin(mat.shape)
mat = np.mean(mat, axis=axis_m)
return mat
def save_image(file_path, mat):
image = Image.fromarray(mat)
try:
image.save(file_path)
except IOError:
print(("Couldn't write to file {}").format(file_path))
raise
return file_path
if __name__ == '__main__':
print("Start......")
sinogram = np.load("E:/Tomo_data/tomo/sinogrambefore.npy")
ncore = mp.cpu_count() - 1
(height, width) = sinogram.shape
angles = np.linspace(0.0, 360.0, height) * np.pi / 180.0
center = tomopy.find_center_vo(
np.expand_dims(sinogram[0:height // 2 + 1: 5], 1), ncore=ncore)
save_image("E:/Tomo_data/tomo/sino_before.tif", sinogram)
print("Center of rotation before {}".format(center))
nmean = np.mean(sinogram)
sinogram[sinogram <=0.0] = nmean
# sinogram = -np.log(sinogram)
rec_image = tomopy.recon(np.expand_dims(sinogram, 1), angles, center=center, algorithm="gridrec", ncore=ncore)
rec_image = tomopy.circ_mask(rec_image, axis=0, ratio=1.0)[0]
save_image("E:/Tomo_data/tomo/rec_image_before.tif", rec_image)
# After correction
sinogram = np.load("E:/Tomo_data/tomo/sinogramafter.npy")
save_image("E:/Tomo_data/tomo/sino_after.tif", sinogram)
center = tomopy.find_center_vo(
np.expand_dims(sinogram[0:height // 2 + 1: 5], 1), ncore=ncore)
print("Center of rotation after {}".format(center))
nmean = np.mean(sinogram)
sinogram[sinogram <=0.0] = nmean
# sinogram = -np.log(sinogram)
rec_image = tomopy.recon(np.expand_dims(sinogram, 1), angles, center=center, algorithm="gridrec", ncore=ncore)
rec_image = tomopy.circ_mask(rec_image, axis=0, ratio=1.0)[0]
save_image("E:/Tomo_data/tomo/rec_image_after.tif", rec_image)
print("Done!")
I can see in your sinograms there're values <=0. This will result black reconstructed image. You can fix that by this:
nmean = np.mean(sinogram)
sinogram[sinogram<= 0.0] = nmean
from tomopy.
Thank You. I think there is something definately wrong from my side.
Can I request you try the al sample. Which I have shared on google drive. If it is possible. May be I can definately know whats going wrong on my side. Using this code-
import tomopy
import numpy as np
from PIL import Image
import multiprocessing as mp
import algotom.prep.correction as corr
def load_image(file_path):
try:
mat = np.asarray(Image.open(file_path), dtype=np.float32)
except IOError:
print(("No such file or directory: {}").format(file_path))
raise
if len(mat.shape) > 2:
axis_m = np.argmin(mat.shape)
mat = np.mean(mat, axis=axis_m)
return mat
def save_image(file_path, mat):
image = Image.fromarray(mat)
try:
image.save(file_path)
except IOError:
print(("Couldn't write to file {}").format(file_path))
raise
return file_path
if __name__ == '__main__':
print("Start......")
# Load data, note that the projections are in the range of 0-360 degree
proj = np.load("E:/Tomo_data/tomo/proj.npy")
flat = np.mean(np.load("E:/Tomo_data/tomo/flat.npy"), axis=0)
dark = np.mean(np.load("E:/Tomo_data/tomo/dark.npy"), axis=0)
ncore = mp.cpu_count() - 1
(depth, height, width) = proj.shape
angles = np.linspace(0.0, 360.0, depth) * np.pi / 180.0
idx = 30
# Before tilted correction
sinogram = (proj[:, idx] - dark[idx]) / (flat[idx] - dark[idx])
# Find center of rotation:
# Reduce number of projections as 3600 projections are more than enough
# for finding the center. Note that we need to pass 180-degree sinogram
# for the finding method.
center = tomopy.find_center_vo(
np.expand_dims(sinogram[0:depth // 2 + 1: 5], 1), ncore=ncore)
sinogram = -np.log(sinogram)
rec_image = tomopy.recon(np.expand_dims(sinogram, 1), angles, center=center, algorithm="gridrec", ncore=ncore)
rec_image = tomopy.circ_mask(rec_image, axis=0, ratio=1.0)[0]
save_image("E:/Tomo_data/tomo/rec_image_before.tif", rec_image)
# Find center at different height for calculating the tilt angle
list_center = []
for i in range(0, height, height // 2 - 1):
print("Find center at slice {}".format(i))
sinogram = (proj[0:depth // 2 + 1:5, i] - dark[i]) / (flat[i] - dark[i])
center = tomopy.find_center_vo(np.expand_dims(sinogram, 1), ncore=ncore)
print("Center is {}".format(center))
list_center.append([i, center])
list_center = np.asarray(list_center)
# Find the tilt angle using linear fit
tilt_angle = -np.rad2deg(np.arctan(np.polyfit(list_center[:, 0], list_center[:, 1], 1)[0]))
print("Tilt angle: {}".format(tilt_angle))
# tilt_angle = -0.5729386976835696
# Generate tilted sinogram using algotom
sino_tilted = corr.generate_tilted_sinogram(proj, idx, tilt_angle)
flat_line = corr.generate_tilted_profile_line(flat, idx, tilt_angle)
dark_line = corr.generate_tilted_profile_line(dark, idx, tilt_angle)
sinogram = corr.flat_field_correction(sino_tilted, flat_line, dark_line)
center = tomopy.find_center_vo(np.expand_dims(sinogram, 1), ncore=ncore)
print("Center after tilt correction is {}".format(center))
# save_image("E:/Tomo_data/tomo/sino_image.tif", sinogram)
sinogram = -np.log(sinogram)
rec_image = tomopy.recon(np.expand_dims(sinogram, 1), angles, center=center, algorithm="gridrec", ncore=ncore)
rec_image = tomopy.circ_mask(rec_image, axis=0, ratio=1.0)[0]
save_image("E:/Tomo_data/tomo/rec_image_after.tif", rec_image)
print("Done!")
from tomopy.
That code is the same code I sent you before and it worked. Your raw data is tiff as I understand. Are you sure it's the same code? One thing I can suggest is to use tomopy.find_center_vo(np.expand_dims(sinogram, 1), ncore=1), set ncore=1 to check. If in the workflow you're using parallel processing on top of find_center_vo, it may return weird results.
Out of that, I leave the fun of debugging codes to you, e.g. save intermediate output to tiff, print data shape,... It's good learning experience.
from tomopy.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
from tomopy.
Related Issues (20)
- information about h5 files HOT 4
- Current TomoPy version 1.11 has unknown SIRT error HOT 5
- Which tomopy algorithms do you typically use? HOT 4
- Installation with GPU support HOT 5
- Issue with mproc.distribute_jobs HOT 1
- Importing error HOT 10
- How to Choose Divisor Value for Data normalization HOT 1
- ModuleNotFoundError: TomoPy links to compiled components which are installed separately and loaded using ctypes.util.find_library(). A required library, tomo-recon, was not found. HOT 8
- How to output the 3 D visualization results HOT 4
- Improve documentation terminology for ROI in normalize_roi HOT 2
- Missing dimension check in gridrec
- Help me in MLEM HOT 1
- GPU Support on Windows 10 HOT 1
- FileNotFoundError: Could not find module 'libtomopy-gridrec.dll' (or one of its dependencies). Try using the full path with constructor syntax. HOT 2
- tomopy.recon with OSEM: blank image with num_block>=3 for num_iter>=2 HOT 1
- Is FBP actually BP in tomopy? What does "filters are not implemented" in FBP mean? HOT 1
- Reconstruction units using different algorithms HOT 3
- Nondeterministic output of remove_ring() HOT 11
- cuda error when installing the tomopy on a computer of Window 10 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tomopy.