2 // chemins des lignes de niveaux
4 // une ligne = un chemin
6 __constant__ int pathDi[PSIZE_I][PSIZE_J-1] =
38 __constant__ int pathDj[PSIZE_I][PSIZE_J-1] =
71 // declare texture reference for 2D int texture
72 texture<int, 2, cudaReadModeElementType> tex_img_in ;
73 texture<int, 2, cudaReadModeElementType> tex_img_estim ;
74 texture<int, 2, cudaReadModeElementType> tex_img_lniv ;
77 __constant__ float tangente[] = {0.000, 0.268, 0.577, 1.000} ;
79 __global__ void kernel_calcul_paths( int2 * d_paths, unsigned int r){
81 unsigned int idpath = 0 ;
82 int ic, jc, iprec, jprec ;
84 unsigned int basepath = 0 ;
87 for (int a=0 ; a< 4 ; a++){ // les 4 angles 0,15,30 et 45
88 for (int p=0 ; p< r ; p++){ // les r points
89 ic = r-1 - floor(tangente[a]*p + offset) ;
91 d_paths[idpath*(r-1)+p-1].x = ic - iprec ;
92 d_paths[idpath*(r-1)+p-1].y = 1 ;
99 for (int a=2 ; a>0 ; a--){ // les 2 angles 60 et 75
100 for (int p=0 ; p< r ; p++){ // les r points
101 jc = floor(tangente[a]*p + offset) ;
103 d_paths[idpath*(r-1)+p-1].x = -1 ;
104 d_paths[idpath*(r-1)+p-1].y = jc - jprec ;
113 for (int a=0 ; a< 6 ; a++){ // les 6 angles 90,105,120,135,150,165
114 for (int p=0 ; p<r-1 ; p++){ // les r points
115 d_paths[idpath*(r-1)+p].x = -d_paths[(idpath - basepath)*(r-1)+p].y ;
116 d_paths[idpath*(r-1)+p].y = d_paths[(idpath - basepath)*(r-1)+p].x ;
123 for (int a=0 ; a< 6 ; a++){ // les 6 angles 180,195,210,225,240,255
124 for (int p=0 ; p<r-1 ; p++){ // les r points
125 d_paths[idpath*(r-1)+p].x = -d_paths[(idpath - basepath)*(r-1)+p].x ;
126 d_paths[idpath*(r-1)+p].y = -d_paths[(idpath - basepath)*(r-1)+p].y ;
133 for (int a=0 ; a< 6 ; a++){ // les 6 angles 270,285,300,315,330,345
134 for (int p=0 ; p<r-1 ; p++){ // les r points
135 d_paths[idpath*(r-1)+p].x = d_paths[(idpath - basepath)*(r-1)+p].y ;
136 d_paths[idpath*(r-1)+p].y = -d_paths[(idpath - basepath)*(r-1)+p].x ;
143 __global__ void kernel_init_estim_from_img_in(unsigned int * d_estim, unsigned int L, unsigned int H, unsigned int r){
144 // coordonnes du point dans l'image
145 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
146 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
147 unsigned int pos = i*L +j ;
148 unsigned int ic , jc, ng ;
150 if( (i>r)&&(i<H-r)&&(j>r)&&(j<L-r) ){
152 for (ic = i - r ; ic <= i + r ; ic++){
153 for (jc = j - r ; jc <= j + r ; jc++){
154 ng += tex2D(tex_img_in, jc, ic ) ;
157 d_estim[ pos ] = ng/((2*r+1)*(2*r+1)) ;
161 d_estim[ pos ] = tex2D(tex_img_in, j, i) ;
165 __global__ void kernel_neutre_estim_from_img_in( unsigned int * d_estim, unsigned int L, unsigned int H ){
166 // coordonnes du point dans l'image
167 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
168 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
169 unsigned int pos = i*L +j ;
171 d_estim[ pos ] = tex2D(tex_img_in, j, i) ;
176 __global__ void kernel_init_estim_from_img_in_global_mem(unsigned int * d_data, unsigned int * d_estim,
177 unsigned int L, unsigned int H, unsigned int r){
178 // coordonnes du point dans l'image
179 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
180 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
181 unsigned int pos = i*L +j ;
182 unsigned int ic , jc, ng ;
184 if( (i>r)&&(i<H-r)&&(j>r)&&(j<L-r) ){
186 for (ic = i - r ; ic <= i + r ; ic++){
187 for (jc = j - r ; jc <= j + r ; jc++){
188 ng += d_data[ ic*L + jc ] ;
191 d_estim[ pos ] = ng/((2*r+1)*(2*r+1)) ;
195 __global__ void kernel_estim_next_step_global_mem(unsigned int * d_estim, unsigned int * d_lniv, unsigned int L, unsigned int H, unsigned int p){
196 // coordonnes du point dans l'image
197 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
198 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
199 unsigned int pos = i*L +j ;
201 d_estim[ pos ] = ( tex2D(tex_img_in, j, i) + p*d_lniv[ pos ] )/(1+p) ;
205 __global__ void kernel_estim_next_step_texture(unsigned int * d_estim, unsigned int L, unsigned int H, unsigned int p){
206 // coordonnes du point dans l'image
207 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
208 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
209 unsigned int pos = i*L +j ;
211 d_estim[ pos ] = ( tex2D(tex_img_in, j, i) + p*tex2D(tex_img_lniv, j, i ))/(1+p) ;
215 __global__ void kernel_estim_next_step_global_mem(unsigned int * d_estim, unsigned int * d_lniv, unsigned int * d_data,
216 unsigned int L, unsigned int H, unsigned int p){
217 // coordonnes du point dans l'image
218 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
219 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
220 unsigned int pos = i*L +j ;
222 d_estim[ pos ] = ( d_data[ pos ] + p*d_lniv[ pos ])/(1+p) ;
226 __global__ void kernel_levelines_global_mem(unsigned int * img_in, unsigned int * img_out, unsigned int L, unsigned int H)
228 // coordonnes du point dans l'image
229 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
230 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
231 //unsigned int spos = threadIdx.x * blockDim.y + threadIdx.y ;
233 // nb de points par chemin
234 int lpath = PSIZE_J ;
235 unsigned int ic, jc, zc, pos = i*L+j;
237 unsigned int mse_min, mse_cur, val ;
241 if((i>lpath)&&(i<H-lpath)&&(j>lpath)&&(j<L-lpath)){
242 for( idpath=0; idpath < PSIZE_I ; idpath++) {
249 for( idpix=0; idpix < lpath-1 ; idpix++ ) {
250 ic += pathDi[idpath][idpix] ;
251 jc += pathDj[idpath][idpix] ;
257 // critere de selection du chemin ( SUM_(X2) - SUM_(X)2 / lpath )
258 // a ameliorer pour vitesse
259 mse_cur = ( mse.y - ( mse.x / lpath ) * mse.x ) ;
264 if ( mse_cur < mse_min ) {
270 img_out[ i*L + j ] = val / lpath ;
274 __global__ void kernel_levelines_texture(unsigned int * img_out, unsigned int L, unsigned int H)
276 // coordonnes du point dans l'image
277 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
278 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
279 //unsigned int spos = threadIdx.x * blockDim.y + threadIdx.y ;
281 // nb de points par chemin
282 int lpath = PSIZE_J ;
283 unsigned int ic, jc, zc ;
285 unsigned int mse_min, mse_cur, val ;
289 if( (i >=lpath )&&( i<= (H-lpath) )&&( j>=lpath )&&( j<=(L-lpath) ) ){
290 for( idpath=0; idpath < PSIZE_I ; idpath++) {
293 zc = tex2D(tex_img_estim, j, i) ;
296 for( idpix=0; idpix < lpath-1 ; idpix++ ) {
297 ic += pathDi[idpath][idpix] ;
298 jc += pathDj[idpath][idpix] ;
299 zc = tex2D(tex_img_estim, jc, ic) ;
303 // critere de selection du chemin ( SUM_(X2) - SUM_(X)2 / lpath )
304 // a ameliorer pour vitesse
305 mse_cur = ( mse.y - ( mse.x*mse.x / lpath ) ) ;
310 if ( mse_cur < mse_min ) {
316 img_out[ i*L + j ] = val / lpath ;
318 else img_out[ i*L + j ] = 0 ;
322 __global__ void kernel_dir_levelines_texture(unsigned int * dir, unsigned int L, unsigned int H)
324 // coordonnes du point dans l'image
325 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
326 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
327 //unsigned int spos = threadIdx.x * blockDim.y + threadIdx.y ;
329 // nb de points par chemin
330 int lpath = PSIZE_J ;
331 unsigned int ic, jc, zc ;
333 unsigned int mse_min, mse_cur, val ;
337 if( (i >=lpath )&&( i<= (H-lpath) )&&( j>=lpath )&&( j<=(L-lpath) ) ){
338 for( idpath=0; idpath < PSIZE_I ; idpath++) {
341 zc = tex2D(tex_img_estim, j, i) ;
344 for( idpix=0; idpix < lpath-1 ; idpix++ ) {
345 ic += pathDi[idpath][idpix] ;
346 jc += pathDj[idpath][idpix] ;
347 zc = tex2D(tex_img_estim, jc, ic) ;
351 // critere de selection du chemin ( SUM_(X2) - SUM_(X)2 / lpath )
352 // a ameliorer pour vitesse
353 mse_cur = ( mse.y - ( mse.x*mse.x / lpath ) ) ;
358 if ( mse_cur < mse_min ) {
364 dir[ i*L + j ] = val ;
372 __global__ void kernel_trace_levelines_texture(unsigned int * dir, unsigned int * img_out,
373 unsigned int L, unsigned int H, unsigned int pas, unsigned int ng){
374 // coordonnes du point dans l'image
375 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
376 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;;
378 // nb de points par chemin
379 int lpath = PSIZE_J ;
380 unsigned int ic, jc, idpix ;
381 unsigned int idpath ;
383 img_out[ i*L + j ] = tex2D(tex_img_estim, j, i ) ;
385 if ( !(i%pas+j%pas)&&(i>=lpath)&&(i<=H-lpath)&&(j>=lpath)&&(j<=L-lpath) ){
388 idpath = dir[ic*L+jc] ;
389 img_out[ ic*L+jc ] = ng ;
390 for ( idpix=0 ; idpix < lpath-1 ; idpix++ ){
391 ic += pathDi[idpath][idpix] ;
392 jc += pathDj[idpath][idpix] ;
393 img_out[ ic*L + jc ] = ng ;