Вы находитесь на странице: 1из 4

Ce programme effectue le remplissage d'une rgion d'une image en mode format pgm

rcursive un bourdonnement Test


des noyaux d'quivalence et hum pixels de voisinage. * /

#include <stdio.h>
#include <stdlib.h>

/ * Dclarer une fonction qui alloue dynamiquement affecte pointeur signal aux
pointeurs um qui sera une matrice * /
** alocarMatriz int (lignes, colonnes int int) {

int i;

matrizAlocada int ** = (int **) calloc (lignes, sizeof (int *));

for (i = 0; i <Lines; i ++) {


matrizAlocada [i] = (int *) calloc (colonnes, sizeof (int));

matrizAlocada arrire;

/ * Une fonction Desclaro Qui crit matrizImg A * /


int ** escreveMatriz (FICHIER imgPGM *, ** matrizImg int, int colonnes, lignes int)
{

int i, j;

for (i = 0; i <Lines; i ++) {

for (j = 0; j <colonnes; j ++) {

fscanf (imgPGM, "% d", et (matrizImg [i] [j]));

matrizImg arrire;
}

/ * Dclarer une fonction qui imprime un tableau * /


void print (int ** matrizImg, colonnes int, lignes int, int max, char aux []) {

int i, j;

printf ( "% s \ n", aux);


printf ( "% d% d \ n" colonnes, les ranges);
printf ( "% d \ n", pas de maximum);

for (i = 0; i <Lines; i ++) {


for (j = 0; j <colonnes; j ++) {
printf ( "% d", matrizImg [i] [j]);
}

printf ( "\ n");

retour;
}

/ * Dclarer une fonction qui peint hum pixels droit * /


Peinture vide (** matrizImg int, int i, j, int NOVACOR) {

matrizImg [i] [j] = NOVACOR;

retour;
}

/ * Dclarer une fonction qui juge le voisin pour dterminer si elle peint ou non *
/
julgarVizinho vide (** matrizImg int, int colonnes, des lignes int, int i, j, CR
int, int NOVACOR) {

/ * Ici, tchque SI CE juger un pixel dans la matrice, ce qui provoque des erreurs
Non,
Tchque est une couleur et le mme, et le pixel tchque Ja De Il a t peint * /

if ((i> = 0) && (j> = 0) && (j <= (colonnes-1)) && ((i <= Lignes-1))) {

if ((CR = Novacor) && ((i-1)> = 0) && ((j-1)> = 0) && (matrizImg [i - 1]! [j - 1]


== couleur)) {

Peinture (matrizImg i-1, j-1, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes i-1, j-1, COR, NOVACOR);

if ((CR = Novacor) && ((i-1)> = 0) && (matrizImg [i - 1]! [j] == couleur)) {

Peinture (matrizImg i-1, j, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes, i-1, j, CR, NOVACOR);


}

if ((CR = NOVACOR) && (i-1> = 0) && ((j + 1) <(colonnes)) && (j + 1 = 8) &&


(matrizImg !! [i - 1] [j + 1 ] == CR)) {

Peinture (matrizImg i-1, j + 1, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes i-1, j + 1, COR, NOVACOR);


}

if ((CR = Novacor) && ((j-1)> = 0) && (matrizImg [i] [j - 1]! == couleur)) {

Peinture (matrizImg, i, j-1, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes, i, j-1, COR, NOVACOR);


}
if ((Cr = NOVACOR) && ((j + 1) <(colonnes)) && (j + 1! = 8) && (matrizImg [i] [j +
1] == CR)) {

Peinture (matrizImg i, j + 1, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes, i, j + 1, COR, NOVACOR);

if ((Cr = NOVACOR) && ((i + 1) <(lignes)) && ((j-1)> = 0) && (i + 1! = 8) &&


(matrizImg [i + 1] [j - 1] == CR)) {

Paint (matrizImg, i + 1, j-1, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes, i + 1, j-1, COR, NOVACOR);

if ((CR = NOVACOR) && ((i + 1) <(lignes)) && (i + 1 = 8) && (matrizImg [I + 1] !! -


== CR) [j 1]) {

Paint (matrizImg, i + 1, j, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes, i + 1, j, CR, NOVACOR);

if ((Cr = NOVACOR) && ((i + 1) <(lignes)) && ((j + 1) <(colonnes)) && (j + 1! = 8)


&& (i + 1! = 8) (- == CR matrizImg [i + 1] [1 j])) {&&

Peinture (matrizImg, i + 1, j + 1, NOVACOR);

julgarVizinho (matrizImg, des colonnes, des lignes, i + 1, j + 1, COR, NOVACOR);

retour;
}

int main (int argc, char const * argv []) {

int ** matrizImg;
Int colonnes, des lignes, max, la couleur, la colonne, la ligne, Novacor;
aux caractres [3];
FICHIER * imgPGM;
les coordonnes du fichier *;

/ * J'ouvre OS * Fichiers /
imgPGM = fopen (argv [1], "r");
Coordonnes = fopen (argv [2] "r");

/ * Tchque si elle n'a pas t possible d'ouvrir des fichiers OS image et peinture
* /

if ((imgPGM == null) || (coordonnes == null)) {

printf ( "Erreur!");

/ * Si elle est bien, en commenant l'objectif de ce programme * /


} Else {

/ * Tout d'abord je scanne les donnes du fichier crire Power Un tableau * /


fscanf (imgPGM, "% s \ n", aux);
fscanf (imgPGM, "% d% d \ n", et les colonnes et lignes);
/ * Espace pour Allouer un tableau * /
matrizImg = alocarMatriz (lignes, colonnes);
fscanf (imgPGM, "% d \ n", et non pas au maximum);

Вам также может понравиться