/* ==================================== */ int32_t lwshedtopo_lreconsdilat( struct xvimage *g, struct xvimage *f, int32_t connex) /* reconstruction de g sous f */ /* g : image marqueur */ /* f : image masque */ /* connex : 4 ou 8 */ /* resultat dans g */ /* ==================================== */ { #undef F_NAME #define F_NAME "lwshedtopo_lreconsdilat" uint8_t *F = UCHARDATA(f); int32_t rs = rowsize(f); /* taille ligne */ int32_t cs = colsize(f); /* taille colonne */ int32_t ds = depth(f); /* nb plans */ int32_t N = rs * cs * ds; int32_t *CM; // component mapping ctree * CT; // component tree if ((rowsize(g) != rs) || (colsize(g) != cs) || (depth(g) != ds)) { fprintf(stderr, "%s: incompatible sizes\n", F_NAME); return 0; } ComponentTree(F, rs, N, connex, &CT, &CM); Reconstruction(g, f, CM, CT); ComponentTreeFree(CT); free(CM); return(1); } /* lwshedtopo_lreconsdilat() */
/* ==================================== */ int32_t lreconseros( struct xvimage *g, struct xvimage *f, int32_t connex) /* reconstruction de g sur f */ /* g : image marqueur */ /* f : image masque */ /* connex : 4 ou 8 */ /* resultat dans g */ /* ==================================== */ { #undef F_NAME #define F_NAME "lreconseros" int32_t ret, i; int32_t rs = rowsize(f); /* taille ligne */ int32_t cs = colsize(f); /* taille colonne */ int32_t ds = depth(f); /* nb plans */ int32_t N = rs * cs * ds; uint8_t *F = UCHARDATA(f); uint8_t *G = UCHARDATA(g); if ((rowsize(g) != rs) || (colsize(g) != cs) || (depth(g) != ds)) { fprintf(stderr, "%s: incompatible sizes\n", F_NAME); return 0; } for (i = 0; i < N; i++) F[i] = NDG_MAX - F[i]; for (i = 0; i < N; i++) G[i] = NDG_MAX - G[i]; ret = lwshedtopo_lreconsdilat(g, f, connex); for (i = 0; i < N; i++) G[i] = NDG_MAX - G[i]; return(ret); } /* lreconseros() */
/* ==================================== */ int32_t ldesfilsclairs3d(struct xvimage * image, struct xvimage * mask, int32_t connexmin) /* ==================================== */ #undef F_NAME #define F_NAME "ldesfilsclairs3d" { int32_t x; uint8_t *F = UCHARDATA(image); uint8_t *M; int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t ps = rs * cs; /* taille plan */ int32_t ds = depth(image); /* nombre plans */ int32_t N = ds * ps; /* taille image */ mctopo3d_init_topo3d(); /* ---------------------------------------------------------- */ /* calcul du resultat */ /* ---------------------------------------------------------- */ if (mask) { if ((rowsize(mask) != rs) || (colsize(mask) != cs) || (depth(mask) != ds)) { fprintf(stderr, "%s: tailles image et mask incompatibles\n", F_NAME); return 0; } M = UCHARDATA(mask); if (connexmin == 6) { for (x = 0; x < N; x++) /* init : empile les points candidats */ if (M[x] && (mctopo3d_filclair6(F, x, rs, ps, N))) F[x] = mctopo3d_alpha26m(F, x, rs, ps, N); } else { for (x = 0; x < N; x++) /* init : empile les points candidats */ if (M[x] && (mctopo3d_filclair26(F, x, rs, ps, N))) F[x] = mctopo3d_alpha6m(F, x, rs, ps, N); } } else { if (connexmin == 6) { for (x = 0; x < N; x++) /* init : empile les points candidats */ if (mctopo3d_filclair6(F, x, rs, ps, N)) F[x] = mctopo3d_alpha26m(F, x, rs, ps, N); } else { for (x = 0; x < N; x++) /* init : empile les points candidats */ if (mctopo3d_filclair26(F, x, rs, ps, N)) F[x] = mctopo3d_alpha6m(F, x, rs, ps, N); } } mctopo3d_termine_topo3d(); return 1; } /* ldesfilsclairs3d() */
/* ==================================== */ int32_t ldespuits3d(struct xvimage * image, struct xvimage * mask, int32_t connexmin) /* ==================================== */ #undef F_NAME #define F_NAME "ldespuits3d" { int32_t i; uint8_t *F = UCHARDATA(image); uint8_t *M; int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t ps = rs * cs; /* taille plan */ int32_t ds = depth(image); /* nombre plans */ int32_t N = ds * ps; /* taille image */ mctopo3d_init_topo3d(); /* ---------------------------------------------------------- */ /* calcul du resultat */ /* ---------------------------------------------------------- */ if (mask) { if ((rowsize(mask) != rs) || (colsize(mask) != cs) || (depth(mask) != ds)) { fprintf(stderr, "%s: tailles image et mask incompatibles\n", F_NAME); return 0; } M = UCHARDATA(mask); if (connexmin == 6) { for (i = 0; i < N; i++) if (M[i] && (mctopo3d_well6(F, i, rs, ps, N))) F[i] = mctopo3d_alpha6p(F, i, rs, ps, N); } else { for (i = 0; i < N; i++) if (M[i] && (mctopo3d_well26(F, i, rs, ps, N))) F[i] = mctopo3d_alpha26p(F, i, rs, ps, N); } } else { if (connexmin == 6) { for (i = 0; i < N; i++) if (mctopo3d_well6(F, i, rs, ps, N)) F[i] = mctopo3d_alpha6p(F, i, rs, ps, N); } else { for (i = 0; i < N; i++) if (mctopo3d_well26(F, i, rs, ps, N)) F[i] = mctopo3d_alpha26p(F, i, rs, ps, N); } } mctopo3d_termine_topo3d(); return 1; } /* ldespics3d() */
/* ==================================== */ int32_t ldilat_ldilat( struct xvimage *f, struct xvimage *m, int32_t xc, int32_t yc) /* m : masque representant l'element structurant */ /* xc, yc : coordonnees du "centre" de l'element structurant */ /* ==================================== */ { int32_t x; /* index muet de pixel */ int32_t y; /* index muet (generalement un voisin de x) */ register int32_t i, j; /* index muet */ register int32_t k, l; /* index muet */ int32_t rs = rowsize(f); /* taille ligne */ int32_t cs = colsize(f); /* taille colonne */ int32_t N = rs * cs; /* taille image */ int32_t rsm = rowsize(m); /* taille ligne masque */ int32_t csm = colsize(m); /* taille colonne masque */ uint8_t *M = UCHARDATA(m); uint8_t *F = UCHARDATA(f); uint8_t *H; /* image de travail */ int32_t sup; int32_t t; if (depth(f) != 1) { fprintf(stderr, "ldilat_ldilat: cette version ne traite pas les images volumiques\n"); return 0; } H = (uint8_t *)calloc(1,N*sizeof(char)); if (H == NULL) { fprintf(stderr,"ldilat_ldilat() : malloc failed for H\n"); return(0); } for (x = 0; x < N; x++) H[x] = F[x]; for (y = 0; y < cs; y++) for (x = 0; x < rs; x++) { sup = NDG_MIN; for (j = 0; j < csm; j += 1) for (i = 0; i < rsm; i += 1) { t = (int32_t)M[j * rsm + i]; if (t) { l = y + j - yc; k = x + i - xc; if ((l >= 0) && (l < cs) && (k >= 0) && (k < rs) && ((int32_t)H[l * rs + k] + t > sup)) sup = (int32_t)H[l * rs + k] + t; } } F[y * rs + x] = (uint8_t)mcmin(sup, NDG_MAX); } free(H); return 1; }
/* ==================================== */ int32_t lordermaxima(struct xvimage *image, struct xvimage *order, int32_t connex, int32_t nblabels) /* ==================================== */ /*! \fn int32_t lordermaxima(struct xvimage *image, struct xvimage *order, int32_t connex, int32_t nblabels) \param image (entrée) : une image \param order (entrée/sortie) : labels définissant les maxima (de 1 à nbmaxima, 0 pour les non-maxima) \param connex (entrée) : 4 ou 8 (2D), 6, 18 ou 26 (3D) \param nblabels (entrée) : nombre de maxima plus 1 \return code erreur : 0 si échec, 1 sinon \brief ordonne les labels sur les maxima par altitude croissante */ #undef F_NAME #define F_NAME "lordermaxima" { int32_t i; int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t ds = depth(image); /* nb plans */ int32_t ps = rs * cs; /* taille plan */ int32_t N = ps * ds; /* taille image */ uint8_t *F = UCHARDATA(image); /* l'image de depart */ int32_t *O = SLONGDATA(order); /* l'image de labels */ int32_t *A; // table de correspondance pour le tri int32_t *T; // table avec l'altitude de chaque maximum if ((rowsize(order) != rs) || (colsize(order) != cs) || (depth(order) != ds)) { fprintf(stderr, "%s: incompatible image sizes\n", F_NAME); exit(0); } A = (int32_t *)malloc(nblabels * sizeof(int32_t)); T = (int32_t *)malloc(nblabels * sizeof(int32_t)); if ((A == NULL) || (T == NULL)) { fprintf(stderr, "%s() : malloc failed\n", F_NAME); return(0); } for (i = 0; i < nblabels; i++) A[i] = i; for (i = 0; i < N; i++) if (O[i]) T[O[i]] = (int32_t)F[i]; i_TriRapideStochastique (A, T, 1, nblabels-1); for (i = 1; i < nblabels; i++) T[A[i]] = i; for (i = 0; i < N; i++) if (O[i]) O[i] = T[O[i]]; free(A); free(T); return 1; } // lordermaxima()
int32_t StreamGArecursif(struct xvimage *ga, int32_t x, Lifo *FIFO, int32_t *Label, int32_t *alt, uint8_t *G) #undef F_NAME #define F_NAME "LPEGrapheAreteValuee" { int32_t rs = rowsize(ga); /* taille ligne */ int32_t cs = colsize(ga); /* taille colonne */ int32_t N = rs * cs; /* taille image */ uint8_t *F = UCHARDATA(ga); int32_t labStream,k,u,y; Label[x] = IN_PROCESS; LifoPush(FIFO, x); for(k = 0; k < 4; k++) if((u = incidente(x, k, rs, N)) != -1) if(F[u] == G[x]){ switch(k){ case 0: y = x+1; break; /* EST */ case 1: y = x-rs; break; /* NORD */ case 2: y = x-1; break; /* OUEST */ case 3: y = x+rs; break; /* SUD */ } if(Label[y] == NO_LABEL) { labStream = StreamGArecursif(ga, y, FIFO, Label, alt,G); if( (labStream >= 0) || ( (*alt) < (int32_t)G[x]) ) return labStream; } else if (Label[y] >= 0){ //(*alt) = G[y]; return Label[y]; } } (*alt) = (int32_t)G[x]; return NO_LABEL; }
/* ==================================== */ int32_t ldespics(struct xvimage * image, struct xvimage * mask, int32_t connexmin) /* ==================================== */ #undef F_NAME #define F_NAME "ldespics" { int32_t i; uint8_t *F = UCHARDATA(image); uint8_t *M; int32_t rs = image->row_size; int32_t cs = image->col_size; int32_t N = rs * cs; if (depth(image) != 1) { fprintf(stderr, "%s: cette version ne traite pas les images volumiques\n", F_NAME); exit(0); } /* ---------------------------------------------------------- */ /* calcul du resultat */ /* ---------------------------------------------------------- */ if (mask) { if ((rowsize(mask) != rs) || (colsize(mask) != cs) || (depth(mask) != 1)) { fprintf(stderr, "%s: tailles image et mask incompatibles\n", F_NAME); exit(0); } M = UCHARDATA(mask); if (connexmin == 8) { for (i = 0; i < N; i++) if (M[i] && (typetopo8(F, i, rs, N) == PEAK)) F[i] = alpha4m(F, i, rs, N); } else { for (i = 0; i < N; i++) if (M[i] && (typetopo(F, i, rs, N) == PEAK)) F[i] = alpha8m(F, i, rs, N); } } else { if (connexmin == 8) { for (i = 0; i < N; i++) if (typetopo8(F, i, rs, N) == PEAK) F[i] = alpha4m(F, i, rs, N); } else { for (i = 0; i < N; i++) if (typetopo(F, i, rs, N) == PEAK) F[i] = alpha8m(F, i, rs, N); } } return 1; } /* ldespics() */
/* Returns (in the form of a 4-connected GA) the edges that link two points with different labels */ struct xvimage *SeparatingEdge(struct xvimage *labels) #undef F_NAME #define F_NAME "mSeparatingEdge" { struct xvimage *ga; int32_t *lab = SLONGDATA(labels); int32_t rs = rowsize(labels); /* taille ligne */ int32_t cs = colsize(labels); /* taille colonne */ int32_t N = rs * cs; /* taille image */ int32_t i,j,u,x,y; if( (ga = allocGAimage(NULL, rs, cs, 1, VFF_TYP_GABYTE)) == NULL) { fprintf(stderr,"%s: ne peut allouer de GA \n", F_NAME); exit(1); } uint8_t *F = UCHARDATA(ga); /* le resultat */ memset(F,0,2*N); /* les aretes horizontales */ for(j = 0; j < cs; j++) for(i = 0; i < rs -1; i++){ u = j * rs + i; x = Sommetx(u,N,rs); y = Sommety(u,N,rs); if(lab[x] != lab[y]) F[u] = 255; } /* puis les aretes verticales */ for(j = 0; j < cs -1; j++) for(i = 0; i < rs; i++){ u = N + j * rs + i; x = Sommetx(u,N,rs); y = Sommety(u,N,rs); if(lab[x] != lab[y]) F[u] = 255; } return ga; }
/** * Description not yet available. * \param */ void lmatrix::allocate(int nrl, int nrh, int ncl, const ivector& nch) { if (nrl !=nch.indexmin() || nrh !=nch.indexmax()) { cerr << "Incompatible array bounds in " "lmatrix::allocate(int nrl,int nrh,int ncl, const ivector& nch)\n"; ad_exit(1); } if ( (shape = new mat_shape(nrl,nrh,ncl,nch(nch.indexmin())))== 0) { cerr << " Error allocating memory in lmatrix contructor\n"; ad_exit(21); } size_t rs=rowsize(); if ( (m = new lvector [rs]) == 0) { cerr << " Error allocating memory in lmatrix contructor\n"; ad_exit(21); } m -= rowmin(); for (int i=rowmin(); i<=rowmax(); i++) { m[i].allocate(ncl,nch(i)); } }
/** * Description not yet available. * \param */ void dmatrix::allocate(int nrl,int nrh,int ncl,int nch) { if (nrh<nrl) { allocate(); return; } index_min=nrl; index_max=nrh; if ( (m = new dvector [rowsize()]) == 0) { cerr << " Error allocating memory in dmatrix contructor\n"; ad_exit(21); } if ( (shape = new mat_shapex(m))== 0) { cerr << " Error allocating memory in dmatrix contructor\n"; ad_exit(21); } m -= rowmin(); for (int i=rowmin(); i<=rowmax(); i++) { m[i].allocate(ncl,nch); } }
/** * Description not yet available. * \param */ void dmatrix::allocate(int nrl,int nrh,const ivector& ncl,int nch) { if (nrh<nrl) { allocate(); return; } if (nrl !=ncl.indexmin() || nrh !=ncl.indexmax()) { cerr << "Incompatible array bounds in dmatrix(int nrl,int nrh," " int ncl,const ivector& nch)\n"; ad_exit(1); } index_min=nrl; index_max=nrh; if ( (m = new dvector [rowsize()]) == 0) { cerr << " Error allocating memory in dmatrix contructor\n"; ad_exit(21); } if ( (shape = new mat_shapex(m))== 0) { cerr << " Error allocating memory in dmatrix contructor\n"; ad_exit(21); } m -= rowmin(); for (int i=rowmin(); i<=rowmax(); i++) { m[i].allocate(ncl(i),nch); } }
// Construit un RAG a partir d'une partition (label) et d'un ga RAG *construitRAG(struct xvimage *ga, struct xvimage *label, struct xvimage *annexe) #undef F_NAME #define F_NAME "construitRAGOpening" { RAG *rag; int32_t i,x,y,u; int32_t rs = rowsize(label); /* taille ligne */ int32_t cs = colsize(label); /* taille colonne */ int32_t N = rs * cs; /* taille image */ int32_t N_t = 2*N; int32_t *LABEL = SLONGDATA(label); /* l'image de depart */ int32_t nblabels; nblabels = 0; for(i = 0; i < N; i++) if(LABEL[i] > nblabels) nblabels = LABEL[i]; nblabels++; rag = initRAG(nblabels, 4*N); /* Parcourt de toutes les aretes du graphe d'arete F */ for(u = 0; u < N_t; u ++){ // si l'arete est bien ds le GA if( ( (u < N) && (u%rs < rs-1)) || ((u >= N) && (u < N_t - rs))){ x = Sommetx(u, N, rs); y = Sommety(u, N, rs); if(LABEL[x] != LABEL[y]) updateRAGArc(rag, LABEL[x], LABEL[y], UCHARDATA(ga)[u]); } } // Puis calcul les attributs de noeuds du rag attributNoeud(rag,label,ga,annexe); return rag; }
// Calcul les attributs surface et profondeur du RAG void attributNoeud(RAG *rag, struct xvimage *label, struct xvimage *ga, struct xvimage *annexe) { int32_t i; int32_t rs = rowsize(label); /* taille ligne */ int32_t cs = colsize(label); /* taille colonne */ int32_t N = rs * cs; /* taille image */ int32_t *LABEL = SLONGDATA(label); /* les labels */ uint8_t *F; int32_t alt; int32_t l; if (annexe!=NULL) F = UCHARDATA(annexe); for(i = 0; i < rag->g->nsom; i++) { /* tout ca peut se calculer au vol lors de la construction de la LPE */ rag->surface[i] = 0; rag->profondeur[i] = 255; rag->altitude[i] = 0; } for(i = 0; i < N; i++) { alt = altitudePoint(ga, i); l = LABEL[i]; rag->profondeur[l] = mcmin(alt,rag->profondeur[l]); rag->surface[l] ++; if (annexe!=NULL) rag->altitude[l] = F[i]; } }
void GridTestCase::Size() { // TODO on OSX resizing interactively works, but not automated #if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__) EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE); EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE); wxUIActionSimulator sim; wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() + m_grid->GetColSize(0), 5)); sim.MouseMove(pt); wxYield(); sim.MouseDown(); wxYield(); sim.MouseMove(pt.x + 50, pt.y); wxYield(); sim.MouseUp(); wxYield(); CPPUNIT_ASSERT_EQUAL(1, colsize.GetCount()); pt = m_grid->ClientToScreen(wxPoint(5, m_grid->GetColLabelSize() + m_grid->GetRowSize(0))); sim.MouseDragDrop(pt.x, pt.y, pt.x, pt.y + 50); wxYield(); CPPUNIT_ASSERT_EQUAL(1, rowsize.GetCount()); #endif }
void HermBandSVDiv<T>::doRDiv( const GenMatrix<T1>& m, MatrixView<T2> x) const { TMVAssert(m.colsize() == x.colsize()); TMVAssert(m.rowsize() == rowsize()); TMVAssert(x.rowsize() == colsize()); CallSV_RDiv(T(),pimpl->U,pimpl->S,pimpl->U.adjoint(),pimpl->kmax,m,x); }
/* ==================================== */ void lattribheight_inverse(struct xvimage * image) /* ==================================== */ { int32_t i, N = rowsize(image) * colsize(image) * depth(image); uint8_t *pt; for (pt = UCHARDATA(image), i = 0; i < N; i++, pt++) *pt = NDG_MAX - *pt; } // inverse
void SymBandSVDiv<T>::doLDiv( const GenMatrix<T1>& m, MatrixView<T2> x) const { TMVAssert(m.rowsize() == x.rowsize()); TMVAssert(m.colsize() == colsize()); TMVAssert(x.colsize() == rowsize()); CallSV_LDiv(T(),pimpl->U,pimpl->S,pimpl->Vt,pimpl->kmax,m,x); }
/* Calcul de Stream par un algo mixant exploration en profondeur et largeur d'abord des chemins de plus grande pente */ int32_t StreamGAFloat(struct xvimage *ga, int32_t x, Lifo *L, Lifo *B,int32_t *psi, float *G) #undef F_NAME #define F_NAME "LPEGrapheAreteValuee" { // Lifo *B; /* Les bottoms non encore exploré de L */ int32_t rs = rowsize(ga); /* taille ligne */ int32_t cs = colsize(ga); /* taille colonne */ int32_t N = rs * cs; /* taille image */ float *F = FLOATDATA(ga); int32_t y, k, u, z; uint8_t breadth_first; LifoPush(L,x); psi[x] = IN_PROCESS; LifoPush(B,x); while(!LifoVide(B)){ y = LifoPop(B); breadth_first = TRUE; for(k = 0; (k < 4) && (breadth_first == TRUE); k++) if((u = incidente(y, k, rs, N)) != -1) if(F[u] == G[y]){ switch(k){ case 0: z = y+1; break; /* EST */ case 1: z = y-rs; break; /* NORD */ case 2: z = y-1; break; /* OUEST */ case 3: z = y+rs; break; /* SUD */ } if(psi[z] != IN_PROCESS) { if(psi[z] != NO_LABEL){ /* There is an inf-stream under L */ LifoFlush(B); return psi[z]; } else { if(G[z] < G[y]){ LifoPush(L,z); psi[z] = IN_PROCESS; /* z is now the only bottom of L */ LifoFlush(B); LifoPush(B,z); /* hence, switch to depth first */ breadth_first = FALSE; } else{ psi[z] = IN_PROCESS; LifoPush(L,z); /* G[z] == G[y], then z is also a bottom of L */ LifoPush(B,z); } } } } } LifoFlush(B); return NO_LABEL; }
float altitudePointFloat(struct xvimage *ga, int32_t i) { int32_t rs = rowsize(ga); /* taille ligne */ int32_t cs = colsize(ga); /* taille colonne */ int32_t N = rs * cs; /* taille image */ float *F = FLOATDATA(ga); /* l'image de depart */ int32_t k, u; float min = 255; // En theorie ca peut aller bien plus haut attention !!! MAX_FLOAT for(k = 0; k < 4; k++) if( (u = incidente(i, k, rs, N)) != -1) { if((float)F[u] < min) min = (float)F[u]; } return min; }
int32_t altitudePoint(struct xvimage *ga, int32_t i) { int32_t rs = rowsize(ga); /* taille ligne */ int32_t cs = colsize(ga); /* taille colonne */ int32_t N = rs * cs; /* taille image */ uint8_t *F = UCHARDATA(ga); /* l'image de depart */ int32_t k, min, u; min = 255; for(k = 0; k < 4; k++) if( (u = incidente(i, k, rs, N)) != -1) { if((int32_t)F[u] < min) min = (int32_t)F[u]; } return min; }
/* =============================================================== */ int32_t l3dboundary(struct xvimage * f) /* =============================================================== */ /* extrait la frontière interne def: {x in F | theta(x) inter Fbar neq emptyset} */ { #undef F_NAME #define F_NAME "l3dboundary" struct xvimage * g; index_t rs, cs, ds, ps, N; index_t x, y, z; uint8_t *F; uint8_t *G; index_t tab[26]; int32_t n, u; rs = rowsize(f); cs = colsize(f); ds = depth(f); F = UCHARDATA(f); ps = rs * cs; N = ps * ds; g = copyimage(f); if (g == NULL) { fprintf(stderr,"%s: copyimage failed\n", F_NAME); return 0; } G = UCHARDATA(g); memset(F, 0, N); for (z = 0; z < ds; z++) for (y = 0; y < cs; y++) for (x = 0; x < rs; x++) if (G[z*ps + y*rs + x]) { Thetacarre3d(rs, cs, ds, x, y, z, tab, &n); for (u = 0; u < n; u++) if (G[tab[u]] == 0) { F[z*ps + y*rs + x] = NDG_MAX; goto next; } next:; } freeimage(g); return 1; } /* l3dboundary() */
/* =============================================================== */ int32_t ltuf(struct xvimage * image, int32_t connexmin, int32_t rayon) /* =============================================================== */ #undef F_NAME #define F_NAME "ltuf" { struct xvimage * copy; int32_t rs, cs, ds, ps, N; int32_t ndes; rs = rowsize(image); /* taille ligne */ cs = colsize(image); /* taille colonne */ ps = rs * cs; /* taille plan */ ds = depth(image); /* nombre plans */ N = ds * ps; /* taille image */ if (ds == 1) /* ======================= 2D ========================*/ { copy = copyimage(image); if (copy == NULL) { fprintf(stderr, "%s: copyimage failed\n", F_NAME); return 0; } do { if (! lhthindelta(image, NULL, rayon, connexmin)) { fprintf(stderr, "%s: lhthindelta failed\n", F_NAME); return 0; } ndes = p_despics(image, connexmin); if (! lhtkernu(image, copy, connexmin)) { fprintf(stderr, "%s: lhtkernu failed\n", F_NAME); return 0; } if (ndes) memcpy(UCHARDATA(copy), UCHARDATA(image), N); } while (ndes); } else /* ============================== 3D ================================*/ { fprintf(stderr, "%s: 3D Not Yet Implemented\n", F_NAME); return 0; } freeimage(copy); return 1; } /* ltuf() */
double altitudePointDouble(struct xvimage *ga, int32_t i) { int32_t rs = rowsize(ga); /* taille ligne */ int32_t cs = colsize(ga); /* taille colonne */ int32_t N = rs * cs; /* taille image */ double *F = DOUBLEDATA(ga); /* l'image de depart */ int32_t k, u; //double min = 956036423.000000; double min = 1000000000000000000000000000000.0; // En theorie ca peut aller bien plus haut attention !!! MAX_FLOAT for(k = 0; k < 4; k++) if( (u = incidente(i, k, rs, N)) != -1) { if(F[u] < min) min = F[u]; } return min; }
/* Attention Label est suppose alloue a la bonne taille ... */ int32_t flowMappingDouble(struct xvimage* ga, int32_t* Label) #undef F_NAME #define F_NAME "LPEGrapheAreteValuee" { int32_t rs = rowsize(ga); /* taille ligne */ int32_t cs = colsize(ga); /* taille colonne */ int32_t N = rs * cs; /* nb_som GA */ int32_t i,som, nb_labs, labstream; double *G; Lifo *FIFO, *B; FIFO = CreeLifoVide(N); B = CreeLifoVide(N); // printf("MAX_DBL %lf \n", DBL_MAX); if( (G = malloc(sizeof(double) * N)) == NULL){ fprintf(stderr,"%s: erreur de malloc \n", F_NAME); exit(0); } /* Initialisation */ for(i = 0; i < N; i++){ G[i] = altitudePointDouble(ga,i); Label[i] = NO_LABEL; } nb_labs = -1; /* Boucle principale */ for(i = 0; i < N; i++){ if(Label[i] == NO_LABEL){ labstream = StreamGADouble(ga,i,FIFO,B,Label, G); if(labstream == NO_LABEL){ nb_labs++; while(!LifoVide(FIFO)){ som = LifoPop(FIFO); Label[som] = nb_labs; }// while(!LifoVide(L)) } else { while(!LifoVide(FIFO)){ som = LifoPop(FIFO); Label[som] = labstream; }//while(!LifoVide(L)) }//if(!labstream) }//if(Label[i] == -1) } LifoTermine(FIFO); LifoTermine(B); free(G); return nb_labs+1; }
/* ==================================== */ int32_t lerosfast(struct xvimage *f, uint8_t *mask) /* mask : masque du 8-voisinage representant l'element structurant */ /* ==================================== */ { int32_t x; /* index muet de pixel */ int32_t y; /* index muet (generalement un voisin de x) */ int32_t k; /* index muet */ int32_t rs = rowsize(f); /* taille ligne */ int32_t cs = colsize(f); /* taille colonne */ int32_t N = rs * cs; /* taille image */ uint8_t *F = UCHARDATA(f); uint8_t *H; /* image de travail */ uint8_t inf; if (depth(f) != 1) { fprintf(stderr, "ldilatfast: cette version ne traite pas les images volumiques\n"); return 0; } H = (uint8_t *)calloc(1,N*sizeof(char)); if (H == NULL) { fprintf(stderr,"lerosfast() : malloc failed for H\n"); return(0); } for (x = 0; x < N; x++) H[x] = F[x]; for (x = 0; x < N; x++) { inf = H[x]; /* l'ES est reflexif */ for (k = 0; k < 8; k += 1) { if (mask[k]) /* element structurant */ { y = voisin(x, k, rs, N); if ((y != -1) && (H[y] < inf)) inf = H[y]; #ifdef BORDZERO if (y == -1) inf = NDG_MIN; #endif } } /* for k */ F[x] = inf; } free(H); return 1; }
/* ==================================== */ void lshowpoint(struct xvimage * image1, int32_t x, int32_t y, int32_t z) /* ==================================== */ #undef F_NAME #define F_NAME "lshowpoint" { int32_t rs, cs, ds, ps; rs = rowsize(image1); cs = colsize(image1); ds = depth(image1); ps = rs * cs; if (datatype(image1) == VFF_TYP_1_BYTE) { uint8_t *pt1 = UCHARDATA(image1); #ifdef DEBUG printf("rs=%d cs=%d ds=%d type=byte x=%d y=%d z=%d\n", rs, cs, ds, x, y, z); #endif printf("%d\n", pt1[z * ps + y * rs + x]); } else if (datatype(image1) == VFF_TYP_4_BYTE) { int32_t *pt1 = SLONGDATA(image1); #ifdef DEBUG printf("rs=%d cs=%d ds=%d type=long x=%d y=%d z=%d\n", rs, cs, ds, x, y, z); #endif printf("%ld\n", (long int)pt1[z * ps + y * rs + x]); } else if (datatype(image1) == VFF_TYP_FLOAT) { float *pt1 = FLOATDATA(image1); #ifdef DEBUG printf("rs=%d cs=%d ds=%d type=float x=%d y=%d z=%d\n", rs, cs, ds, x, y, z); #endif printf("%g\n", pt1[z * ps + y * rs + x]); } else { fprintf(stderr, "%s: bad data type\n", F_NAME); return; } } // lshowpoint()
/* ==================================== */ void subimage( struct xvimage * image1, struct xvimage * image2) /* difference de 2 images */ /* ==================================== */ { int32_t i; uint8_t *pt1, *pt2; int32_t rs, cs, d, N; rs = rowsize(image1); cs = colsize(image1); d = depth(image1); N = rs * cs * d; for (pt1 = UCHARDATA(image1), pt2 = UCHARDATA(image2), i = 0; i < N; i++, pt1++, pt2++) *pt1 = *pt1 - *pt2; } /* subimage() */
/** * Description not yet available. * \param */ void lmatrix::allocate(int nrl,int nrh,int ncl,int nch) { if ( (shape = new mat_shape(nrl,nrh,ncl,nch))== 0) { cerr << " Error allocating memory in lmatrix contructor\n"; ad_exit(21); } size_t rs = rowsize(); if ( (m = new lvector [rs]) == 0) { cerr << " Error allocating memory in lmatrix contructor\n"; ad_exit(21); } m -= rowmin(); for (int i=rowmin(); i<=rowmax(); i++) { m[i].allocate(ncl,nch); } }
/** * Description not yet available. * \param */ void dmatrix::allocate(ad_integer nrl,ad_integer nrh) { if (nrh<nrl) { allocate(); return; } index_min=nrl; index_max=nrh; if ( (m = new dvector [rowsize()]) == 0) { cerr << " Error allocating memory in dmatrix contructor\n"; ad_exit(21); } if ( (shape = new mat_shapex(m))== 0) { cerr << " Error allocating memory in dmatrix contructor\n"; ad_exit(21); } m -= rowmin(); }