Use next cell if too many logging
messages…
import logging
LOG_FMT = '%(filename)s - l.%(lineno)d - %(levelname)s: %(message)s'
logging.basicConfig(format=LOG_FMT, level=logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
%matplotlib notebook
import matplotlib.pyplot as plt
from ipywidgets import interactive
from ipywidgets import IntSlider
def wimshow(slice_id):
plt.imshow(blend[slice_id, :, :, :])
plt.show()
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 4
1 get_ipython().run_line_magic('matplotlib', 'notebook')
2 import matplotlib.pyplot as plt
----> 4 from ipywidgets import interactive
5 from ipywidgets import IntSlider
7 def wimshow(slice_id):
ModuleNotFoundError: No module named 'ipywidgets'
Blockmatching example with vt-python
¶
In the following examples we try to register two angles of a multi-angle image (multiple observations of the same object at the same time but from different angles) using blockmatching
.
import numpy as np
from timagetk.io.image import _image_from_url
/home/aurele/Soft/timagetk/src/timagetk/components/labelled_image.py:32: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)
from tqdm.autonotebook import tqdm
Estimation of rigid transformation¶
It is now possible to estimate the rigid transformation registering image tilt2
onto top
:
from vt import blockmatching as vt_blockmatching
vt_blockmatching(flo_path, ref_path, params="-trsf-type rigid -py-ll 2", out_file_path=trsf_rig_path)
Read the estimated rigid transformation¶
To access the estimated rigid transformation, you have to load it using the following commands:
from vt import vtTransformation as Trsf
rig_trsf = Trsf(trsf_rig_path)
You can now print a summary of the Trsf
object:
print(rig_trsf)
Print the transformation matrix¶
To access the 4x4 matrix defining the transformation:
print(rig_trsf.copy_to_array())
Apply transformation to floating image¶
To obtain the registration of image tilt2
on the top
reference, you now have to apply the previously estimated transformation rig_trsf
to image tilt2
.
It is done as follow:
from vt import apply_trsf as vt_apply_trsf
vt_apply_trsf(flo_path, trsf_rig_path, ref=ref_path, params="-linear", out_file_path=reg_rig_path)
OPTIONAL - TimageTK - Visualization of the rigid registration¶
from timagetk.io import imread
flo_img = imread(flo_path)
ref_img = imread(ref_path)
reg_img = imread(reg_rig_path)
from timagetk.components.multi_channel import combine_channels
blend = combine_channels([ref_img, reg_img], ['green', 'red'])
interactive_plot = interactive(wimshow, slice_id=IntSlider(min=0, max=blend.get_shape('z')-1, step=1, value=0))
output = interactive_plot.children[-1]
interactive_plot
Estimation of affine transformation¶
trsf_aff_path = '/tmp/p58-t0-tilt2_on_top-affine.trsf'
reg_aff_path = '/tmp/p58-t0-tilt2_on_top-affine.tif'
from vt import blockmatching as vt_blockmatching
params = "-trsf-type affine -py-hl 5 -py-ll 1"
vt_blockmatching(flo_path, ref_path, params=params, out_file_path=trsf_aff_path)
from vt import apply_trsf as vt_apply_trsf
vt_apply_trsf(flo_path, trsf_aff_path, ref=ref_path, params="-linear", out_file_path=reg_aff_path)
reg_img = imread(reg_aff_path)
from timagetk.components.multi_channel import combine_channels
blend = combine_channels([ref_img, reg_img], ['green', 'red'])
interactive_plot = interactive(wimshow, slice_id=IntSlider(min=0, max=blend.get_shape('z')-1, step=1, value=0))
output = interactive_plot.children[-1]
interactive_plot
Estimation of deformable transformation¶
trsf_def_path = '/tmp/p58-t0-tilt2_on_top-deformable.trsf'
reg_def_path = '/tmp/p58-t0-tilt2_on_top-deformable.tif'
from vt import blockmatching as vt_blockmatching
params = "-trsf-type vectorfield -py-hl 5 -py-ll 1"
vt_blockmatching(flo_path, ref_path, trsf_init=trsf_aff_path, params=params, out_file_path=trsf_def_path)
from vt import apply_trsf as vt_apply_trsf
vt_apply_trsf(flo_path, trsf_def_path, ref=ref_path, params="-linear", out_file_path=reg_def_path)
reg_img = imread(reg_def_path)
from timagetk.components.multi_channel import combine_channels
blend = combine_channels([ref_img, reg_img], ['green', 'red'])
interactive_plot = interactive(wimshow, slice_id=IntSlider(min=0, max=blend.get_shape('z')-1, step=1, value=0))
output = interactive_plot.children[-1]
interactive_plot