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 __global__ void kernel_init_estim_from_img_in(unsigned int * d_estim, unsigned int L, unsigned int H, unsigned int r){
78 // coordonnes du point dans l'image
79 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
80 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
81 unsigned int pos = i*L +j ;
82 unsigned int ic , jc, ng ;
84 if( (i>r)&&(i<H-r)&&(j>r)&&(j<L-r) ){
86 for (ic = i - r ; ic <= i + r ; ic++){
87 for (jc = j - r ; jc <= j + r ; jc++){
88 ng += tex2D(tex_img_in, jc, ic ) ;
91 d_estim[ pos ] = ng/((2*r+1)*(2*r+1)) ;
95 d_estim[ pos ] = tex2D(tex_img_in, j, i) ;
99 __global__ void kernel_init_estim_from_img_in_global_mem(unsigned int * d_data, unsigned int * d_estim,
100 unsigned int L, unsigned int H, unsigned int r){
101 // coordonnes du point dans l'image
102 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
103 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
104 unsigned int pos = i*L +j ;
105 unsigned int ic , jc, ng ;
107 if( (i>r)&&(i<H-r)&&(j>r)&&(j<L-r) ){
109 for (ic = i - r ; ic <= i + r ; ic++){
110 for (jc = j - r ; jc <= j + r ; jc++){
111 ng += d_data[ ic*L + jc ] ;
114 d_estim[ pos ] = ng/((2*r+1)*(2*r+1)) ;
118 __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){
119 // coordonnes du point dans l'image
120 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
121 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
122 unsigned int pos = i*L +j ;
124 d_estim[ pos ] = ( tex2D(tex_img_in, j, i) + p*d_lniv[ pos ] )/(1+p) ;
128 __global__ void kernel_estim_next_step_texture(unsigned int * d_estim, unsigned int L, unsigned int H, unsigned int p){
129 // coordonnes du point dans l'image
130 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
131 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
132 unsigned int pos = i*L +j ;
134 d_estim[ pos ] = ( tex2D(tex_img_in, j, i) + p*tex2D(tex_img_lniv, j, i ))/(1+p) ;
138 __global__ void kernel_estim_next_step_global_mem(unsigned int * d_estim, unsigned int * d_lniv, unsigned int * d_data,
139 unsigned int L, unsigned int H, unsigned int p){
140 // coordonnes du point dans l'image
141 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
142 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
143 unsigned int pos = i*L +j ;
145 d_estim[ pos ] = ( d_data[ pos ] + p*d_lniv[ pos ])/(1+p) ;
149 __global__ void kernel_levelines_global_mem(unsigned int * img_in, unsigned int * img_out, unsigned int L, unsigned int H)
151 // coordonnes du point dans l'image
152 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
153 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
154 //unsigned int spos = threadIdx.x * blockDim.y + threadIdx.y ;
156 // nb de points par chemin
157 int lpath = PSIZE_J ;
158 unsigned int ic, jc, zc, pos = i*L+j;
160 unsigned int mse_min, mse_cur, val ;
164 if((i>lpath)&&(i<H-lpath)&&(j>lpath)&&(j<L-lpath)){
165 for( idpath=0; idpath < PSIZE_I ; idpath++) {
172 for( idpix=0; idpix < lpath-1 ; idpix++ ) {
173 ic += pathDi[idpath][idpix] ;
174 jc += pathDj[idpath][idpix] ;
180 // critere de selection du chemin ( SUM_(X2) - SUM_(X)2 / lpath )
181 // a ameliorer pour vitesse
182 mse_cur = ( mse.y - ( mse.x / lpath ) * mse.x ) ;
187 if ( mse_cur < mse_min ) {
193 img_out[ i*L + j ] = val / lpath ;
197 __global__ void kernel_levelines_texture(unsigned int * img_out, unsigned int L, unsigned int H)
199 // coordonnes du point dans l'image
200 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
201 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;
202 //unsigned int spos = threadIdx.x * blockDim.y + threadIdx.y ;
204 // nb de points par chemin
205 int lpath = PSIZE_J ;
206 unsigned int ic, jc, zc ;
208 unsigned int mse_min, mse_cur, val ;
212 if((i>lpath)&&(i<H-lpath)&&(j>lpath)&&(j<L-lpath)){
213 for( idpath=0; idpath < PSIZE_I ; idpath++) {
216 zc = tex2D(tex_img_estim, j, i) ;
219 for( idpix=0; idpix < lpath-1 ; idpix++ ) {
220 ic += pathDi[idpath][idpix] ;
221 jc += pathDj[idpath][idpix] ;
222 zc = tex2D(tex_img_estim, jc, ic) ;
226 // critere de selection du chemin ( SUM_(X2) - SUM_(X)2 / lpath )
227 // a ameliorer pour vitesse
228 mse_cur = ( mse.y - ( mse.x / lpath ) * mse.x ) ;
233 if ( mse_cur < mse_min ) {
239 img_out[ i*L + j ] = val / lpath ;
246 __global__ void kernel_levelines_only_texture(unsigned int * img_out, unsigned int L, unsigned int H)
248 // coordonnes du point dans l'image
249 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
250 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;;
251 //unsigned int spos = threadIdx.x * blockDim.y + threadIdx.y ;
253 // nb de points par chemin
254 int lpath = PSIZE_J ;
255 unsigned int ic, jc ;
257 unsigned int mse_min, mse_cur ;
259 //extern __shared__ uint2 mse[] ;
262 if((i>lpath)&&(i<H-lpath)&&(j>lpath)&&(j<L-lpath)){
263 for( idpath=0; idpath < PSIZE_I ; idpath++) {
266 mse.x = tex2D(tex_img_in, i, j) ;
267 mse.y = tex2D(tex_img_in, i, j)*tex2D(tex_img_in, i, j) ;
268 for( idpix=0; idpix < lpath-1 ; idpix++ ) {
269 ic += pathDi[idpath][idpix] ;
270 jc += pathDj[idpath][idpix] ;
271 mse.x += tex2D( tex_img_in, ic, jc ) ;
272 mse.y += tex2D( tex_img_in, ic, jc ) * tex2D( tex_img_in, ic, jc ) ;
274 // critere de selection du chemin ( SUM_(X2) - SUM_(X)2 / lpath )
275 // a ameliorer pour vitesse
276 mse_cur = ( mse.y - ( mse.x / lpath ) * mse.x ) ;
278 if ( mse_cur < mse_min ) {
285 img_out[ i*L + j ] = mse_min / lpath ;
290 __global__ void kernel_trace_levelines(unsigned int * img_in, unsigned int * dir, unsigned int * img_out,
291 unsigned int L, unsigned int H, unsigned int pas, unsigned int ng){
292 // coordonnes du point dans l'image
293 unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
294 unsigned int j = blockIdx.y*blockDim.y + threadIdx.y;;
296 // nb de points par chemin
297 int lpath = PSIZE_J ;
298 unsigned int ic, jc, idpix ;
299 unsigned int idpath ;
301 img_out[ i*L + j ] = img_in[ i*L + j ] ;
303 if ( !(i%pas+j%pas)&&(i>lpath)&&(i<H-lpath)&&(j>lpath)&&(j<L-lpath) ){
306 idpath = dir[ic*L+jc] ;
307 img_out[ ic*L+jc ] = ng ;
308 for ( idpix=0 ; idpix < lpath-1 ; idpix++ ){
309 ic += pathDi[idpath][idpix] ;
310 jc += pathDj[idpath][idpix] ;
311 img_out[ ic*L + jc ] = ng ;