Commit 328b313a authored by Pierre-antoine Comby's avatar Pierre-antoine Comby

un cours de traitement d'image sans image

parent 694e493c
This diff is collapsed.
def harris(image, sigma=10, kappa=0.04):
derivees = gradient(image)
d_x = derivees[0]
d_y = derivees[1]
noyau = noyau_gaussien3(sigma)
#TODO: convol DoG
d_xx_lissee = ndimage.convolve(d_x * d_x,noyau , mode = 'nearest')
d_yx_lissee = ndimage.convolve(d_x * d_y,noyau , mode = 'nearest')
d_yy_lissee = ndimage.convolve(d_y * d_y,noyau , mode = 'nearest')
determinant = d_xx_lissee * d_yy_lissee -d_yx_lissee * d_yx_lissee
trace = d_xx_lissee + d_yy_lissee
image_harris = determinant - kappa * trace * trace
return image_harris
def maxlocal(image_harris, seuil,size_patch=10):
""" Array*float -> Array """
output = np.zeros(image_harris.shape)
voisinage = np.zeros((3,3))
for ligne in range(size_patch,image_harris.shape[0]-size_patch):
for colonne in range(size_patch,image_harris.shape[1]-size_patch):
current_val = image_harris[ligne, colonne]
voisinage = image_harris[ligne - 1: ligne + 2, colonne - 1:colonne + 2].copy()
voisinage[(1,1)] = 0
output[ligne, colonne] = np.logical_and(current_val > seuil,
current_val > np.amax(voisinage))
print(output)
return(output)
def coord_maxlocal(image,seuil,size_patch=3):
#seuil=np.mean(image_extrema)
""" Array -> Array """
x,y = np.nonzero(maxlocal(image,seuil))
return np.array((y,x)).T
def get_corners(pict):
image_harris = harris(pict,sigma=3,kappa=0.06)
corners = coord_maxlocal(image_harris,np.mean(image_harris))
return corners
pict1 = np.array(Image.open("set1-1.png").convert('L'),dtype='float')
pict2 = np.array(Image.open("set1-2.png").convert('L'),dtype='float')
corners1=get_corners(pict1)
corners2=get_corners(pict2)
def calcul_acc_cercles(img_s, rad_min=5, rad_max=100):
#init acc :
[c_max, r_max] = img_s.shape
r_min=1
delta_r = 1
N_r = int((r_max-r_min+delta_r)/delta_r)
delta_c = 1
c_min = 1
N_c = int((c_max-c_min+delta_c)/delta_c)
delta_rad = 1
N_rad = int((rad_max-rad_min+delta_rad)/delta_rad)
acc = np.zeros((N_rad,N_r,N_c))
print("Taille de l'accumulateur" + str(acc.shape))
x,y = np.nonzero(img_s)
for i in range(len(x)):
for r in range(r_min, r_max+1, delta_r):
for c in range(c_min, c_max+1, delta_c):
if (x[i],y[i]) != (r,c):
rad = np.sqrt((r-x[i])**2 + (c-y[i])**2)
if rad < rad_max and rad > rad_min:
i_id = int((r-r_min)/delta_r)
j_id = int((c-c_min)/delta_c)
k_id = int((rad-rad_min)/delta_rad)
acc[k_id,i_id,j_id] += 1 /rad
return acc
def cherche_N_maxima_cercles(accumulateur, exclusion_xy,
exclusion_rayon, N):
accu2 = np.copy(accumulateur)
[rad_max0, c_max0, r_max0] = accumulateur.shape
liste_max = []
for cercle in range(N):
[rayon, w_0, h_0] = np.unravel_index(np.argmax(accu2),accu2.shape)
rayon += 5
w_0 += 1
h_0 += 1
accu2[rayon - exclusion_rayon : rayon + exclusion_rayon,
w_0 -exclusion_xy : w_0 + exclusion_xy,
h_0 - exclusion_xy : h_0 + exclusion_xy] =0
liste_max.append([rayon, w_0, h_0])
return liste_max
\documentclass[openany]{../../cours}
\usepackage{../../raccourcis}
% bug avec minted sinon
\let\framed\relax \let\endframed\relax
\let\shaded\relax \let\endshaded\relax
\let\leftbar\relax \let\endleftbar\relax
\let\snugshade\relax \let\endsnugshade\relax
\usepackage{minted}
\setminted{linenos=true, tabsize=4, fontsize=\small, xleftmargin=5pt, xrightmargin=5pt,bgcolor=gray!10,frame=lines,framesep=2mm}
% Mise en page
\title{Notes de Cours}
\author{Pierre-Antoine Comby}
\teacher{Emmanuel Aldea \& Thomas Rodet}
\module{453 - Traitement d'Image}
\usepackage{multicol}
\begin{document}
\maketitle
\chapter{Introduction au traitement d'image}
\subfile{chap1.tex}
\chapter{Chapitre2}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
......@@ -38,7 +38,8 @@
\newcommand{\ddd}[2]{\frac{\text{d}^2 #1}{\text{d} {#2}^2}}
\newcommand{\dr}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\divv}{\text{div}}
% Macros mieux :)
\newcommand{\grad}{\text{grad}}
%Macros mieux :)
\newcommand{\chimie}[1]{$\mathrm{#1}$}
\newcommand{\chimiecite}[1]{\[\mathrm{#1}\]}
\newcommand{\nchim}{\mathit{n}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment