lformat_imau1_classifier_input.c

Go to the documentation of this file.
00001 /*
00002 *    Copyright (c) 2007. The BATI team. All right reserved.
00003 *
00004 *    This file is part of BATI library.
00005 *
00006 *    BATI library is free software: you can redistribute it and/or modify
00007 *    it under the terms of the GNU General Public License as published by
00008 *    the Free Software Foundation, either version 3 of the License, or
00009 *    (at your option) any later version.
00010 *
00011 *    BATI library  is distributed in the hope that it will be useful,
00012 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *    GNU General Public License for more details.
00015 *
00016 *    You should have received a copy of the GNU General Public License
00017 *    along with BATI library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 /* ************************************************************************* */
00020 /*               lformat_imau1_classifier_input.c                            */
00021 /* ************************************************************************* */
00022 /*          Formatage d'une image de type U1 en structure d'entrée           */
00023 /*                     pour un classifieur                                   */
00024 /*                                                                           */
00025 /* ************************************************************************* */
00026 /*                                                                           */
00027 /*  Dernière modification: 08/12/03                                          */
00028 /*  Créer par: Ramasso E. & Jullien S.                                       */
00029 /*                                                                           */
00030 /* ************************************************************************* */
00031 
00032 
00039 #include "format_imau1_classifier_input.h"
00040 #include "image.h"
00041 #include "proto2D.h"
00042 #include <stdlib.h>
00043 #include <stdio.h>
00044 
00045 
00046 
00062 
00063 /* *************************  LECTURE  *******************************/
00079 param *format_imau1_classifier_input_lect(format_imau1_classifier_input_t *desc, param *ptp, char *debq)
00080 {
00081   char question[500];
00082   int choix;
00083 
00084   sprintf(question, "%s Image entiere (0) ou partielle (1)", debq);
00085   lec_param(question, ptp);
00086   desc->choix = atoi(ptp->rep);
00087   ptp = ptp->next;
00088 
00089 
00090   switch(desc->choix)
00091     {
00092       /* si une partie des donnees */
00093     case IMAGE_PARTIELLE :
00094 
00095       sprintf(question, "%s Coordonnées X du premier point (colonne : 0 a nb colonnes - 1)", debq);
00096       lec_param(question, ptp);
00097       desc->premier_point.Xcol = atoi(ptp->rep);
00098       ptp = ptp->next;
00099       
00100       sprintf(question, "%s Coordonnées Y du premier point (ligne : 0 a nb lignes - 1)", debq);
00101       lec_param(question, ptp);
00102       desc->premier_point.Yrow = atoi(ptp->rep);
00103       ptp = ptp->next;
00104       
00105       sprintf(question, "%s Coordonnées X deuxieme point (colonne : 0 a nb colonnes - 1)", debq);
00106       lec_param(question, ptp);
00107       desc->deuxieme_point.Xcol = atoi(ptp->rep);
00108       ptp = ptp->next;
00109       
00110       sprintf(question, "%s Coordonnées Y deuxieme point (ligne : 0 a nb lignes - 1) ", debq);
00111       lec_param(question, ptp);
00112       desc->deuxieme_point.Yrow = atoi(ptp->rep);
00113       ptp = ptp->next;
00114       
00115       break;
00116 
00117 
00118       /* mise a jour dans init */
00119     case IMAGE_ENTIERE : break;
00120 
00121       /* sinon erreur */
00122     default : 
00123       printf("\nMauvaise reponse\n"); 
00124       exit(1);
00125 
00126     }
00127 
00128   return ptp;
00129 }
00130 
00131 
00132 /* *************************  INITIALISATION  ***************************/
00152 int format_imau1_classifier_input_init(format_imau1_classifier_input_t *desc, imau1 image_u1, data_input *data)
00153 {
00154   printf("\nInit format...");
00155   switch(desc->choix)
00156     {
00157       /* toute l image */
00158     case IMAGE_ENTIERE :
00159       desc->premier_point.Xcol = 0;
00160       desc->premier_point.Yrow = 0;
00161       desc->deuxieme_point.Xcol = image_u1.nc - 1;
00162       desc->deuxieme_point.Yrow = image_u1.nr - 1;
00163       break;
00164 
00165       /* une partie de l image => verif dim */
00166     case IMAGE_PARTIELLE :
00167       if(!(desc->premier_point.Xcol >= 0 && desc->premier_point.Xcol < image_u1.nc &&
00168            desc->premier_point.Yrow >= 0 && desc->premier_point.Yrow < image_u1.nr &&
00169            desc->deuxieme_point.Xcol >= 0 && desc->deuxieme_point.Xcol < image_u1.nc &&
00170            desc->deuxieme_point.Yrow >= 0 && desc->deuxieme_point.Yrow < image_u1.nr &&
00171            desc->deuxieme_point.Xcol - desc->premier_point.Xcol >= 0 &&
00172            desc->deuxieme_point.Yrow - desc->premier_point.Yrow >= 0))
00173         {
00174           printf("\nErreur dimension - coordonnees points invalides\n");
00175           exit(1);
00176         }
00177       
00178       break;
00179 
00180     default :   
00181       printf("\nErreur dans init : choix non valide\n"); 
00182       exit(1);
00183     }
00184 
00185   
00186   /* taille de la nouvelle image */
00187   data->equ_nb_cols = desc->deuxieme_point.Xcol - desc->premier_point.Xcol + 1;
00188   data->equ_nb_rows = desc->deuxieme_point.Yrow - desc->premier_point.Yrow + 1;
00189 
00190   /* l'image image_u1 a ete prealablement lue et initialisee => nc et nr connus */
00191   data->nb_pts = data->equ_nb_cols*data->equ_nb_rows;
00192 
00193   /* mise a jour des champs de data_input */
00194   data->begin = 0;
00195   data->end = data->nb_pts;
00196 
00197   /* init pointeur attributes */
00198   data->attributes = NULL;
00199   
00200   /* init nb attributs */
00201   data->nb_attr = 0;
00202   
00203   printf("OK.");
00204   return 0;
00205 }
00206 
00207 /* *************************  CALCUL  ***************************/
00222 int format_imau1_classifier_input_calc(format_imau1_classifier_input_t *desc, imau1 image_u1, data_input *data)
00223 {
00224   int i,j,k;
00225    printf("Calcul format...");
00226 
00227   /* incrementation nb attributs */
00228   data->nb_attr += 1;
00229 
00230   /* allocation prealablement effectuee de data->attributes */
00231   alloc_classifier_data_input_one_by_one(data);
00232 
00233   /* transfert des donnees de l image dans la structure d entree */
00234   k=0;
00235    for(i=0;i<data->equ_nb_rows;i++)
00236      for(j=0;j<data->equ_nb_cols;j++)
00237        {
00238          data->attributes[data->nb_attr - 1][k] =(float)(image_u1.p[desc->premier_point.Yrow+i][desc->premier_point.Xcol+j]);
00239          k++;
00240        }
00241    printf("OK\n");
00242  
00243    return 0;
00244 }
00245 
00247 

Generated on Tue Apr 22 13:31:02 2008 for donnee1D by  doxygen 1.5.3