dwarfo
Messages postés5Date d'inscriptionvendredi 10 février 2012StatutMembreDernière intervention14 mars 2012
-
8 mars 2012 à 09:58
BunoCS
Messages postés15472Date d'inscriptionlundi 11 juillet 2005StatutModérateurDernière intervention25 mars 2024
-
8 mars 2012 à 11:56
Bonjour,
je cherche à appliquer un filtre de sobel sur une image bitmap 8 bits mais sans librairies.
J'ai vu qu'il existait de nombreux code mais souvent avec des librairies donc ça ne correspond pas à ce que je recherche.
Voilà le code que j'ai fait jusque là. Mais je sais qu'il y a un problème puisque je n'arrive pas à mettre les données d'un pixel dans la matrice pixel.
De plus j'ai un autre problème, quand je retourne les variables : printf("%ld\n",source_info.height);
printf("%ld\n",source_info.width); les nombres ne sont pas ceux de l'image que j'utilise.
Je tiens juste à dire que mes compétences en langage c sont limités...
Je remercie d'avance tout ceux qui pourront m'aider.
//structure defiens bitmap header
struct BITMAPFILEHEADER{
unsigned short type;//type of file (bit map)
unsigned long size;//size of file
unsigned short reserved1;//
unsigned short reserved2;//
unsigned long offsetbits;//off set bits
};
struct BITMAPINFOHEADER{
unsigned long size;//bitmap size
unsigned long width;//width of bitmap
unsigned long height;//hight of bitmap
unsigned short planes;
unsigned short bitcount;
unsigned long compression;// compression ratio (zero for no compression)
unsigned long sizeimage;//size of image
long xpelspermeter;
long ypelspermeter;
unsigned long colorsused;
unsigned long colorsimportant;
};
unsigned long int i=0;//to count pixels readed
unsigned long int j=0;
unsigned long long int S=0;//number of pixcels to read
struct BITMAPFILEHEADER source_head;//to store file header
struct BITMAPINFOHEADER source_info;//to store bitmap info header
//struct SINGLE_PIXEL source_pix;// to store pixcels
int source_pix;
FILE *fp;//file pointer for source file
FILE *Dfp;//file ponter for distenation file
if(!(fp=fopen("Image1.bmp","rb")))//open in binery read mode
{
printf("\can not open file");//prind and exit if file open error
exit(-1);
}
Dfp=fopen("dist.bmp","wb");//opne in binery write mode
//read the headers to souirce file
fread(&source_head,sizeof(struct BITMAPFILEHEADER),1,fp);
fread(&source_info,sizeof(struct BITMAPINFOHEADER),1,fp);
//write the headers to distenation file
fwrite(&source_head,sizeof(struct BITMAPFILEHEADER),1,Dfp);
fwrite(&source_info,sizeof(struct BITMAPINFOHEADER),1,Dfp);
//read, modefy and write pixcels
int pixel [513][514];
int pixel_res[514];
for(i=1;i<512;i++)
{
for(j=2;j<513;j++)
{
//read pixcel form source file
fread(&source_pix,sizeof(struct SINGLE_PIXEL),1,fp);
//printf("%d\n",pixel[i][j]);