# TIFO: Cours recalage
*Comment extraire une frequence cardiaque quand on a une oscillation ?*
:::success
Stabiliser l'image
:::
:::warning
Quand on fait du recalage, on fait des estimations donc par moment l'image "vibre"
:::
La video recalee est plus petite car on prend la plus grande translation de chaque cote.
# Context
## An example

> Ptit poisson, grozyeux
## General principle
:::info
**What is the transformation between 2 frames ?**
For 2 frames $I_2$ and $I_2$, Find $\mathcal T$ to minimize
$$
\mathcal V = Variance(I_1,\mathcal T(I_2))
$$
:::

> Hyper important de verifier
### 2 frames
:::info
The **reference frame** ($I_1$ in our presentation) is the frame we will not modify, considered as the "true" image
:::
:::info
The **studied frame** ($I_2$ in our presentation) is the frame we try to minimize $\mathcal V$
:::
## Model
Choixe of the model to have the best estimation:
- Fourier domain
- Image
- Graph
- Multi-modality
- Un peu complique
## Usual transformations
### Rigid transformation
:::info
Transfo rigide: on ne change pas la structure (les distances) dans l'image
:::


### Non-rigid transformation

:::warning
On ne veut surtout pas faire de transformation non-rigide
:::
*Pourquoi ?*
On risque de creer des deformations locales (dans notre exemple: corriger le mouvement du coeur)
## Transformation estimation
Classical estimation for the entire image analysis:
$$
\mathcal T = (\mathcal R, T)
$$
with:
$$
\mathcal R=
\begin{pmatrix}
\alpha a &\alpha b\\
\alpha c&\alpha d
\end{pmatrix} = \alpha\mathcal R'\\
T=(d_x, d_y)
$$
Case of $\mathcal R$:
If there is a rotation:
$$
\mathcal R=
\begin{pmatrix}
\alpha \cos(\theta) &-\alpha \sin(\theta)\\
\alpha \sin(\theta)&\alpha \cos(\theta)
\end{pmatrix} = \alpha\mathcal R'
$$
$\alpha$ is the scale factor
$$
(I_2\mathcal R+T)-I_1 = min(\mathcal V)\\
S = \mathcal T(I_2)=(I_2\mathcal R + T)\\
\forall (x,y)\in I_2: S(x,y)=I_2(x',y')
$$
with the estimated $\mathcal R$ and $T$, $[x'\quad y']=[x\quad y]\mathcal R+T$
# Key-points
## Principle
:::info
**Objectives**
- Points which are interesting $I_1$
- Find their equivalent in $I_2$
- Estimate the transform between the 2 sets of points
We want to solve
$$
P_2=P_2\times\mathcal R+\mathcal T
$$
Where $P_1$ and $P_2$ are the sets of points of the 2 frames we seek to match, $\mathcal R$ is the "rotation" matrix. $\mathcal T=(d_x, d_y)$ is the translation

:::
## The solution

:::warning
En fonction de la version d'OpenCV il peut y avoir un soucis avec la matrice $\mathcal M$ (elle peut etre $3\times 3$ au lieu de $2\times 3$)
:::
# Applications
- Sequence stabilization
- Reconstruction
- Optical flow
- Similarity
- Comparison (evolution of a tumor etc.)
# Recalage
## keuwa ?
Deux images $S$ et $C$: cherche $T$ tel que $T(S)$ ressemble a $C$

:::warning
Les notations sont pourries ici
:::
## Applications
:::danger
Outil **fondamental** en analyse d'images medicales, mais pas uniquement
:::
- Ou ailleurs en imagerie ?
- Creation d'images panoramiques
- Mosaiques
- Astronomie


:::warning
On ne cherche pas sur toute l'image les points-cles, on se restreint a une certaine zone
:::
# Systemes par mosaique
Ce type d'approche consiste a **construire les images panoramiques** a partir d'une **serie d'images** prises avec le meme systeme optique. On peut, par exemple, utiliser une camera en rotation autour de son centre optique

Evidemment, un nombre arbitraire d'images peut etre utilise

# Exemples en imagerie medicale
## Recalage
:::info
**Definition**
Consiste a trouver une transformation spatiale permettant d'aligner une image (source ou *flottante*) sur une autre (cible ou *reference*)
:::
En anglais:
- Image registration
- Image matching

Recalage monomodal ou multimodal:
- Monomodal: meme modalites
- Multimodale: modalites differentes

Recalage intra ou inter-sujets


## Exemples
### Intra-patient, mono-modalite
Exemple: evolution de lesions (images IRM d'un patient atteint de SEP a quelques mois d'intervalle)


:::success
C'est flou !
:::

Pour trouver quelles sont les zones qui ont evolue
### Intra-patien, multi-modalite
Exemple: fusion d'informations provenant de 2 modalites differentes


### Inter-patient, intra-modalite
Exemple: segmentation a partir d'un *atlas* anatomique

### Extension en 3D

# Recalage en imagerie medicale
Reconstruction d'un volume 3D
- A partir d'une serie de coupes 2D contigues (microscopie, epaisseur de coupe de 60nm environ)


Evolution temporelle


> Brain-shift

> Developpement cerebral
Comparaison entre differents sujets:


Fusion de modalite

## Recap

# Principe des methodes de recalage
## Critere de similarite
Supposons que l'on se donne un critere de similarite: $Simil(I, J)$ qui mesure la "*ressemblance*" entre 2 images $I$ et $J$


On choisit egalement une famille de transformation $\mathcal F$
:::info
Le probleme de recalage s'ecrit alors comme:
$$
argmin_{T\in\mathcal F} Simil(T(I), J)=?
$$
:::
## Methode de recalage
- Structures (primitives) a mettre en correspondance
- Critere de similarite
- Transformation
- Optimisation

## Primitives geometriques
:::info
Structures particulieres dans l'image
:::
- Points, courbes, surfaces
- Extraits automatiquement ou manuellement



> Detection des primitives: ici points de forte courbure
:::info
- Primitives intrinseques
- Primitives extrinseques
:::
## Primitives intrinseques
- Structurent intrinseques au patient
- Information pertinente presente dans les 2 jeus de donnees
- Points
- Courbes (contours)
- Surfaces segmenteees
- Volumes
- Points anatomiques
- Identifies manuellement par l'operateur
- Isole automatiquement
## Primitives extrinseques
Reperes externes, visibles dans les 2 modalites
- fixees au patient ou a la table d'examen
- Invasifs
- Cadre stereitaxique
- Vis dans la boite cranienne
- Non invasifs
- Cadre non visse
- Moule
- Repere colles a la peau
### Avantages
- Permet de recaler des donnees tres differentes
### Inconvenients
- Les marqueurs doivent etre positionnes avant l'acquisition
- Le recalage retrospectif n'est pas possible
Autres reperes exterenes, contention


On fait des moules du patient pour faire des recalages
# Primitives
:::danger
Pas de structures particulieres: tous les voxels de l'image sont utilises
:::
# Critere de similarite

## Dependance lineaire ou affine

## Coefficient de correlation





## Histogramme conjoint


:::success
Quand il est parfait, on a le meme nombre de points a la meme valeur
:::

*A quel histogramme correspond les images ?*

:::success

:::
## Conservation de l'intensite - SSD

## Information mutuelle

### Exemples

## Sommaire

# Optimisation
## Approches geometriques

# Evaluation
## Evaluation qualitative

## Evaluation semi-quantitative

## Evaluation quantitative
