Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

imafill.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: imafill.c,v 1.1 2005/09/09 08:22:47 bellet Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of its specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 00036 #include <stdio.h> 00037 #include <string.h> // For strcpy 00038 #include "idima.h" 00039 #include "iderr.h" 00040 #include "idprint.h" 00041 #include "idio.h" 00042 /******************************************************************************* 00043 * 00044 * Description : Avec des images UCHAR 00045 * Remplit les trous des objets connexes d'une image binaire 00046 * Parametres de sortie : Aucun 00047 * 00048 *******************************************************************************/ 00049 00050 /* FUNCTION DESCRIPTION ************************************************** 00051 00052 IdImaFill (fonction) 00053 00054 RESUME: Rempli les trous ds les objets connexes d'1 image binaire 00055 00056 DESCRIPTION: 00057 Remplit les trous dans les objets connexes d'une image binaire 00058 (Objets blancs sur fond noir). 00059 A noter: un cadre noir de largeur 1 pixel remplace le bord de l'image. 00060 PLUS MAINTENANT ! ... 00061 00062 ATTENTION : L'image source etait modifiee, ainsi que l'image destination. 00063 Ce n'etait pas precise dans la Doc, c'etait peut-etre un Bug.... 00064 Ce n'est plus le cas maintenant (21/4/99) 00065 00066 SYNTAXE: int retCode=IdImaFill (PPIMAGE_UCHAR imSource, PPIMAGE_UCHAR imDest, int connexite); 00067 00068 RETOUR: type : int 00069 role : -1 si echec, sinon le nombre de trous remplis. 00070 00071 PARAMETRES: nom : ims 00072 type : PPIMAGE_UCHAR 00073 role : Pointeur vers l'image source 00074 00075 nom : imd 00076 type : PPIMAGE_UCHAR 00077 role : Pointeur vers l'image resultat 00078 Si ce pointeur est nul, l'image est allouee par 00079 la fonction. NON CE POINTEUR NE PEUT PAS ETRE NULL MW 00080 00081 nom : connexite 00082 type : int 00083 role : connexite des objets: 00084 connexite = 1 : 8-connexite 00085 connexite = 0 : 4-connexite 00086 00087 FICHIER: imafill.c 00088 00089 EXEMPLE: if ( (status=IdImaFill(ims,imd,1)) == -1 ) 00090 IdErrPrintf("ERREUR: %s",IdErrMsg(IdErrno)); 00091 00092 ******************************************************** END DESCRIPTION */ 00093 int 00094 IdImaFill(ims,imd,connexite) 00095 PPIMAGE_UCHAR ims,imd; 00096 int connexite; 00097 { 00098 PPIMAGE_SHORT imo; 00099 PPIMAGE_UCHAR imX,imY; 00100 FILE *fich_res,*fich_mod; 00101 char nom_res[100],nom_mod[100]; 00102 int nb,surf_min=1,x,y; 00103 short val; 00104 unsigned char tval; 00105 /* Controle des l'images **/ 00106 if ( !ims || IdImaType(ims)!=IMA_UCHAR ){ 00107 IdErrno = IDERR_WRONG_TYPE; 00108 return -1; 00109 } 00110 if ( !imd || IdImaType(imd)!=IMA_UCHAR ){ 00111 IdErrno = IDERR_WRONG_TYPE; 00112 return -1; 00113 } 00114 if ( (connexite != 0) && (connexite != 1) ){ 00115 IdErrno = IDERR_INVALID_NUMBER; 00116 return -1; 00117 } 00118 00119 /* On sauve le cadre de largeur un pixel autour de l'image *****/ 00120 /* On repousse vers l'interieur les pixels blancs qui touchent le bord *****/ 00121 /* On incruste un cadre noir de largeur un pixel autour de l'image *****/ 00122 00123 imX=(PPIMAGE_UCHAR)IdImaAlloc(IdImaDimX(ims),2,IMA_UCHAR); 00124 imY=(PPIMAGE_UCHAR)IdImaAlloc(2,IdImaDimY(ims),IMA_UCHAR); 00125 00126 for(x=0;x<IdImaDimX(ims);x++) 00127 { imX[0][x] = ims[0][x]; 00128 imX[1][x] = ims[IdImaDimY(ims)-1][x]; 00129 00130 if (ims[0][x]==255) 00131 { 00132 ims[1][x]=255; 00133 ims[0][x]=0; 00134 } 00135 if (ims[IdImaDimY(ims)-1][x]==255) 00136 { 00137 ims[IdImaDimY(ims)-2][x]=255; 00138 ims[IdImaDimY(ims)-1][x]=0; 00139 } 00140 } 00141 00142 for(y=1;y<IdImaDimY(ims)-1;y++) 00143 { imY[y][0] = ims[y][0]; 00144 imY[y][1] = ims[y][IdImaDimX(ims)-1]; 00145 00146 if (ims[y][0]==255) 00147 { 00148 ims[y][1]=255; 00149 ims[y][0]=0; 00150 } 00151 if (ims[y][IdImaDimX(ims)-1]==255) 00152 { 00153 ims[y][IdImaDimX(ims)-2]=255; 00154 ims[y][IdImaDimX(ims)-1]=0; 00155 } 00156 } 00157 00158 /***** Transformation de l'image en negatif *****/ 00159 for(y=0;y<IdImaDimY(ims);y++) 00160 for(x=0;x<IdImaDimX(ims);x++){ 00161 tval=ims[y][x]; 00162 ims[y][x]= ~tval; 00163 } 00164 00165 /***** Allocation de l'image label et initialisation a zero *****/ 00166 imo=(PPIMAGE_SHORT) IdImaAlloc(IdImaDimX(ims),IdImaDimY(ims),IMA_SHORT); 00167 if ( !imo ) { 00168 IdErrno = IDERR_ALLOC_MEM; 00169 return -1; 00170 } 00171 for(y=0;y<IdImaDimY(imo);y++) 00172 for(x=0;x<IdImaDimX(imo);x++) 00173 imo[y][x]=0; 00174 00175 /***** Recherche des objets (trous) *****/ 00176 00177 /* ! ! ! Nom de fichiers fixes, 1 seul appel a la fois ! ! ! */ 00178 00179 #if ( _SUNC_ ) 00180 strcpy(nom_mod,getenv("HOME")); strcat(nom_mod,"/tmp/ftemp.mod"); 00181 strcpy(nom_res,getenv("HOME")); strcat(nom_res,"/tmp/ftemp.res"); 00182 #else 00183 strcpy(nom_mod,"ftemp.mod"); 00184 strcpy(nom_res,"ftemp.res"); 00185 #endif 00186 if(! (fich_mod=fopen(nom_mod,ID_WFILE_TEXT)) ) { 00187 IdErrno = IDERR_OPEN_FAILED; 00188 IdErrPrintf("ERREUR: %s: %s\n",IdErrMsg(IdErrno),nom_mod); 00189 return -1; 00190 } 00191 if(! (fich_res=fopen(nom_mod,ID_WFILE_TEXT)) ) { 00192 IdErrno = IDERR_OPEN_FAILED; 00193 IdErrPrintf("ERREUR: %s: %s\n",IdErrMsg(IdErrno),nom_res); 00194 return -1; 00195 } 00196 00197 nb=IdImaLabel(ims,imo,surf_min,fich_res,fich_mod,1-connexite); 00198 00199 /* Les connexites des objets et des trous sont complementaires (4 - 8) */ 00200 00201 if(nb == -1) IdErrPrintf("ERREUR: %s\n",IdErrMsg(IdErrno)); 00202 fclose(fich_res);fclose(fich_mod); 00203 00204 /***** Remplissage des trous *****/ 00205 00206 for(y=0;y<IdImaDimY(imd);y++) 00207 for(x=0;x<IdImaDimX(imd);x++) 00208 { 00209 val=imo[y][x]; 00210 if (val==0) imd[y][x]=0; /* val=0 : objets */ 00211 else if (val<nb) imd[y][x]=0; /* 0<val<nb : trous */ 00212 else imd[y][x]=255; /* val=nb : fond */ 00213 } 00214 00215 /***** Liberation memoire *****/ 00216 IdImaFree(imo); 00217 00218 /***** Retour en normal negatif de imd *****/ 00219 00220 for(y=0;y<IdImaDimY(imd);y++) 00221 for(x=0;x<IdImaDimX(imd);x++){ 00222 tval=imd[y][x]; 00223 imd[y][x]= ~tval; 00224 /* MW */ 00225 /* tval=ims[y][x]; 00226 ims[y][x]= ~tval; 00227 */ 00228 } 00229 00230 if (imd!=ims) /* On ne restaure l'image Source QUE si elle est differente */ 00231 /* de l'image destination ... JPRx */ 00232 for(y=0;y<IdImaDimY(imd);y++) 00233 for(x=0;x<IdImaDimX(imd);x++){ 00234 tval=ims[y][x]; 00235 ims[y][x]= ~tval; 00236 } 00237 00238 /* On restaure le cadre de largeur un pixel autour de l'image *****/ 00239 00240 for(x=0;x<IdImaDimX(ims);x++) 00241 { imd[0][x] = imX[0][x]; 00242 imd[IdImaDimY(ims)-1][x] = imX[1][x]; 00243 00244 ims[0][x] = imX[0][x]; 00245 ims[IdImaDimY(ims)-1][x] = imX[1][x]; 00246 } 00247 00248 for(y=1;y<IdImaDimY(ims)-1;y++) 00249 { imd[y][0] = imY[y][0]; 00250 imd[y][IdImaDimX(ims)-1] = imY[y][1]; 00251 00252 ims[y][0] = imY[y][0]; 00253 ims[y][IdImaDimX(ims)-1] = imY[y][1]; 00254 } 00255 00256 IdImaFree(imX); 00257 IdImaFree(imY); 00258 00259 return nb ; 00260 }

Generated on Wed Oct 19 09:28:33 2005 for SIMRI3D by doxygen 1.3.7