• Aucun résultat trouvé

#include <stdio.h> #include <stdlib.h> #define MOT 2

N/A
N/A
Protected

Academic year: 2022

Partager "#include <stdio.h> #include <stdlib.h> #define MOT 2"

Copied!
2
0
0

Texte intégral

(1)

#include <stdio.h>

#include <stdlib.h>

#define MOT 2

void message(char *information);

int main() {

char nom[256], nom1[256], nom2[256], information[2048];

int i,j,ki, kj, taille_dicom, cote, cote2,entete;

float coef[3][3]={1.,2.,1.,2.,4.,2.,1.,2.,1.} ; float somme, calcul;

short int *dicom ; short int *tampon ;

FILE *fichier ;

/* Calcul de la somme des coefficients pour moyenne */

somme = 0.0; for(i=0;i<3;i++) for(j=0;j<3;j++) somme += coef[i][j];

/* Ouverture du fichier contenant l’image */

printf("\nEntrez le nom du fichier image dicom a ouvrir : ");

scanf("%s",nom);

sprintf(nom1,"%s.dcm",nom);

printf("\nEntrez la taille de cette image (nombre de pixels par cote: ");

scanf("%d",&cote);

cote2 = cote*cote;

fichier=fopen(nom1,"rb") ; if(fichier==NULL) {

sprintf(information, "Erreur : le fichier %s n'est pas lisible dans le repertoire courant\n",nom1);

message(information);

}

/* Calcul de la taille du fichier dicom contenant l'image */

fseek(fichier,0,SEEK_END);

taille_dicom = ftell(fichier);

taille_dicom/=MOT;

/* Calcul de la taille de l'entête unique en début de fichier */

entete = taille_dicom - cote2;

/* Allocation d’un pointeur sur le fichier image dicom complet */

dicom = malloc(taille_dicom*sizeof(short int)) ; if(dicom==NULL)

{

sprintf(information, "Erreur : Allocation du fichier dicom impossible lors de sa lecture\n");

message(information);

}

fseek(fichier,0,SEEK_SET);

fread(dicom,taille_dicom,sizeof(short int),fichier) ; fclose(fichier) ;

(2)

/* Filtrage de l’image */

tampon = malloc(cote2*sizeof(short int)) ; if(tampon==NULL)

{

sprintf(information, "Erreur : Allocation de l'image tampon impossible lors du filtrage\n");

message(information);

}

for(i=1; i<cote-1; i++) for(j=1; j<cote-1; j++) {

*(tampon+j+i*cote) = 0;

calcul = 0.0;

for(ki=-1;ki<=1;ki++) for(kj=-1;kj<=1;kj++)

calcul += (coef[ki+1][kj+1] * (float)(*(dicom + entete + j+kj + (i+ki)*cote))) ;

*(tampon+j+i*cote) = (short int)( calcul/somme + 0.5);

}

for(i=1; i<cote-1; i++) for(j=1; j<cote-1; j++)

*(dicom + entete +j+i*cote) = *(tampon+j+i*cote);

free(tampon);

/* Ecriture de l’image dicom filtrée */

sprintf(nom2,"%s-filtre.dcm",nom);

fichier=fopen(nom2,"wb") ; if(fichier==NULL)

{

sprintf(information,"Erreur : le fichier %s ne peut pas etre ecrit dans le répertoire courant\n",nom2);

message(information);

}

fseek(fichier,0,SEEK_SET);

fwrite(dicom,taille_dicom,sizeof(short int),fichier) ; fclose(fichier) ;

/* libération de mémoire */

free(dicom);

sprintf(information,"Le fichier %s a ete ecrit dans le repertoire courant avec succes.\nFin du programme (tapez sur une touche pour fermer)\n",nom2);

message(information);

}

/*---*/

void message(char *information) { printf(information); getch(); exit(1) ; } /*---*/

Références

Documents relatifs

The interrupt option provides each of the input channels with I/O data and service interrupt control which enables the external device to interrupt the computer

All binary licensed software, including any subse- quent updates, is furnished under the licensing provisions of DIGITAL's Standard Terms and Condi- tions of Sale,

For example, a function Python defined in one INCLUDE could not be used in a formula command file.. Precaution: It is disadvised using the order TO DESTROY in

Par exemple, une fonction Python définie dans un INCLUDE ne pourra pas être utilisée dans une formule du fichier de commandes.. Précaution : Il est déconseillé d'utiliser la

[r]

[r]

Ecrire une fonction ´ int simul(int m) qui compare le nombre de couleurs utilis´ ees par l’algo exact et par DSATUR pour colorier m graphes al´ eatoires pour n et p fix´

• On considère un fil fin rigide, enroulé en hélice d'équa- tion : z = hθ (où h est une constante), sur un cylindre dʼaxe Oz, de rayon r et de hauteur totale L. • Un