Skip to content
Snippets Groups Projects
Commit 3ed76f49 authored by fima's avatar fima :beers:
Browse files

simple examples

parent d406f412
No related branches found
No related tags found
No related merge requests found
......@@ -397,7 +397,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.13"
}
},
"nbformat": 4,
......
%% Cell type:code id:1817e01b tags:
``` python
import qim3d
import sys
```
%% Cell type:code id:46caffce tags:
``` python
# Test a simple Tiff file
file_path = "../resources/img3d/NT_10x200x100.tif"
vol = qim3d.io.load(file_path)
print(vol.shape, sys.getsizeof(vol))
```
%% Output
TiffPage 0: TypeError: read_bytes() missing 3 required positional arguments: 'dtype', 'count', and 'offsetsize'
(10, 200, 100) 200144
%% Cell type:code id:8e151674 tags:
``` python
# Test a simple Tiff file
file_path = "../resources/img3d/NT_10x200x100.tif"
vol = qim3d.io.load(file_path, virtual_stack=True)
print(vol.shape, sys.getsizeof(vol))
```
%% Cell type:code id:96b84a09 tags:
``` python
```
%% Cell type:code id:0850abe3 tags:
``` python
# Test a simple H5 file
file_path = "../resources/img3d/small_foram.h5"
vol = qim3d.io.load(file_path, dataset_name="exchange/data")
print(vol.shape, sys.getsizeof(vol))
```
%% Output
(721, 260, 282) 105727584
%% Cell type:code id:b8a73f84 tags:
``` python
# Test a H5 file
file_path = "../resources/img3d/small_foram.h5"
vol = qim3d.io.load(file_path, dataset_name="exchange/data", virtual_stack=True)
print(vol.shape, sys.getsizeof(vol))
```
%% Output
(721, 260, 282) 48
%% Cell type:code id:0a6c8a5a tags:
``` python
# Test a TXRM file
file_path = "/dtu/3d-imaging-center/courses/47511/data/glass_fiber/glass_fiber_2023-08-21_124210/4X-50kV-LE3-13s-1.9mico/glass_fiber_4X-50kV-LE3-13s-1.9mico_recon.txm"
vol = qim3d.io.load(file_path, return_metadata=False)
print(vol.shape, sys.getsizeof(vol))
```
%% Output
(995, 1014, 988) 1993645824
%% Cell type:code id:b4a7e303 tags:
``` python
# Test a TXRM file
file_path = "/home/fima/Downloads/glass_fiber_4X-50kV-LE3-2s-1601_5micro.txrm"
vol, metadata = qim3d.io.load(file_path, return_metadata=True)
print(vol.shape, sys.getsizeof(vol))
print(metadata)
```
%% Output
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Cell In[7], line 3
1 # Test a TXRM file
2 file_path = "/home/fima/Downloads/glass_fiber_4X-50kV-LE3-2s-1601_5micro.txrm"
----> 3 vol, metadata = qim3d.io.load(file_path, return_metadata=True)
4 print(vol.shape, sys.getsizeof(vol))
5 print(metadata)
File ~/qim3d/qim3d/io/load.py:332, in load(path, virtual_stack, dataset_name, return_metadata, contains, **kwargs)
299 """
300 Load data from the specified file or directory.
301
(...)
322 data = load("image.tif", virtual_stack=True)
323 """
324 loader = DataLoader(
325 virtual_stack=virtual_stack,
326 dataset_name=dataset_name,
(...)
329 **kwargs,
330 )
--> 332 return loader.load(path)
File ~/qim3d/qim3d/io/load.py:280, in DataLoader.load(self, path)
276 # Fails
277 else:
278 # Find the closest matching path to warn the user
279 parent_dir = os.path.dirname(path)
--> 280 parent_files = os.listdir(parent_dir)
281 valid_paths = [os.path.join(parent_dir, file) for file in parent_files]
282 similar_paths = difflib.get_close_matches(path, valid_paths)
FileNotFoundError: [Errno 2] No such file or directory: '/home/fima/Downloads'
%% Cell type:markdown id:138d2f38 tags:
# 2D blob detection
Author: Felipe Delestro (fima@dtu.dk)
This Notebook performs a simple blob detection in a 2D image
%% Cell type:code id:61fed336 tags:
``` python
import numpy as np
import qim3d
import matplotlib.pyplot as plt
from skimage.feature import blob_log
```
%% Cell type:markdown id:5d014011 tags:
## Load and prepare the data
%% Cell type:code id:5fa00477 tags:
``` python
# Load the data using the qim3d data loader
vol = qim3d.io.load("../resources/img3d/cement_128x128x128.tif")
vol = qim3d.io.load("../resources/img3d/bone_128x128x128.tif")
```
%% Cell type:code id:5f293c27 tags:
``` python
# Select one slice from the 3D volume
img = vol[32]
```
%% Cell type:code id:541680f2 tags:
``` python
# Check the slice
fig, ax = plt.subplots(figsize=(6,6))
ax.imshow(img, cmap='gray')
ax.set_axis_off()
```
%% Output
%% Cell type:code id:d7427573 tags:
``` python
# Blob detection works for objects brighter than the background, so we invert the image
img = np.invert(img)
```
%% Cell type:code id:c61e6653 tags:
``` python
# Check the slice
fig, ax = plt.subplots(figsize=(6,6))
ax.imshow(img, cmap='gray')
ax.set_axis_off()
```
%% Output
%% Cell type:markdown id:dc0db350 tags:
## Blob detection
%% Cell type:code id:16fb7512 tags:
``` python
detections = blob_log(img, min_sigma=2, max_sigma=6, num_sigma=12, threshold=.02)
print (f"Total of {len(detections)} detected objects")
```
%% Output
Total of 115 detected objects
%% Cell type:markdown id:be984c57 tags:
### Display results
%% Cell type:code id:fa3d997d tags:
``` python
# Compute radii in the 3rd column.
detections[:, 2] = detections[:, 2] * np.sqrt(2)
# Show circles
fig, ax = plt.subplots(figsize=(6, 6))
ax.imshow(img, cmap='gray')
for detection in detections:
y, x, r = detection
c = plt.Circle((x, y), r, color="#FF5733", linewidth=2, fill=False, alpha=0.5)
ax.add_patch(c)
ax.set_axis_off()
plt.show()
```
%% Output
......
%% Cell type:markdown id:f79ab52a tags:
%% Cell type:markdown id:98845dbc tags:
# Simple sinogram check
# Simple interactive sinogram check
author: Felipe Delestro (fima@dtu.dk)
%% Cell type:code id:b5096870 tags:
%% Cell type:code id:4f4a0b0c tags:
``` python
import qim3d
import matplotlib.pyplot as plt
import ipywidgets
import qim3d
import matplotlib.pyplot as plt
import ipywidgets
```
%% Cell type:code id:6b9a1f66 tags:
%% Cell type:code id:6c539f03 tags:
``` python
vol = qim3d.io.load("../resources/img3d/small_foram.h5", dataset_name="exchange/data")
```
%% Cell type:code id:99832d5a tags:
%% Cell type:code id:455a5e35 tags:
``` python
def plot_sinogram(vol, zpos, ypos):
fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(8,10), sharey=True)
axs[0].imshow(vol[zpos,:,:])
axs[0].axhline(ypos, color="#FF6633")
axs[0].axis("off")
axs[1].imshow(vol[:,ypos,:])
axs[1].axis("off")
plt.show()
```
%% Cell type:code id:0395e573 tags:
%% Cell type:code id:634512ff tags:
``` python
ipywidgets.interactive(plot_sinogram,
vol = ipywidgets.fixed(vol),
zpos = ipywidgets.IntSlider(min=0, max=vol.shape[0]-1, value=int(vol.shape[0]/2)),
ypos = ipywidgets.IntSlider(min=0, max=vol.shape[1]-1, value=int(vol.shape[1]/2)))
```
%% Output
interactive(children=(IntSlider(value=360, description='zpos', max=720), IntSlider(value=130, description='ypo…
......
......@@ -219,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.17"
}
},
"nbformat": 4,
......
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment