Академический Документы
Профессиональный Документы
Культура Документы
Practica #01
Asignatura:
Profesor:
Alumno:
Carrera:
Ing. en Mecatrnica
Fecha:
14/02/2015
Primer Programa Aplicando Operadores Para Deteccin de Bordes:
Para este programa se modific el cdigo base asignado desde el curso anterior de PDI
de tal manera que se hiciera la deteccin de bordes de las imgenes, y despus con
este programa aplicar una entidad de vecindad de 3x3 para los tres siguientes
operadores.
f
( E3,1 E3,2 E3,3 ) ( E1,1 E1,2 E1,3 )
x
f
( E3,1 E3,2 E3,3 ) ( E1,1 E1,2 E1,3 )
y
Prewitt W, Prewitt N, Prewitt NW:
/* **********************************************************************
Ver 1.2
Prohibido su uso, distribucion y copia sin autorizacion por parte del autor.
**********************************************************************
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
}gcIMG;
//FUNCIN PRINCIPAL
int main(void)
{ gcIMG *Img,*a,*b;
float *Mask;
int i,j;
Img=gcGetImgBmp("C:\\Users\\makogane\\Desktop\\bleach3.bmp");
Dimenciones(Img);
Mask=Mascara();
a=Convolucion(Img,Mask);
b=Normalizado(a);
gcPutImgBmp("C:\\Users\\makogane\\Desktop\\SOBEL.bmp",b);
gcFreeImg(Img);
free(Mask);
gcFreeImg(b);
system("PAUSE");
return 0;
float* Mascara()
{ int M,N,i,j;
float *A;
scanf("%i",&N);
A=(float *)malloc(M*N*sizeof(float));
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)
{ printf("\n M[%i][%i]=",i,j);
scanf("%f",&*(A+i*N+j));
for(i=0;i<M;i++)
{ printf("\n");
for(j=0;j<N;j++)
printf("%f \t",A[i*M+j]);
return (A);
}
//FUNCIN PARA CONVOLUCION
{ gcIMG *A;
A=gcNewImg(Ima->ancho,Ima->alto);
for(i=1;i<(Ima->alto-1);i++)
{ for(j=1;j<(Ima->ancho-1);j++)
{ A->imx[(i*A->ancho)+j]=((Ima->imx[(((i-1)*Ima->ancho)+(j-1))]*Mask[8])
+(Ima->imx[(((i-1)*Ima->ancho)+j)]*Mask[7])
+(Ima->imx[(((i-1)*Ima->ancho)+(j+1))]*Mask[6])
+(Ima->imx[((i*Ima->ancho)+(j-1))]*Mask[5])
+(Ima->imx[((i*Ima->ancho)+j)]*Mask[4])
+(Ima->imx[((i*Ima->ancho)+(j+1))]*Mask[3])
+(Ima->imx[(((i+1)*Ima->ancho)+(j-1))]*Mask[2])
+(Ima->imx[(((i+1)*Ima->ancho)+j)]*Mask[1])
+(Ima->imx[(((i+1)*Ima->ancho)+(j+1))]*Mask[0]));
return (A);
{ gcIMG *I;
unsigned int i;
float Ma,me,den,fac;
I=gcNewImg(Ima->ancho,Ima->alto);
Ma=Ima->imx[0];
for(i=0;i<Ima->size;i++)
{ Ima->imx[i];
if(Ima->imx[i]>Ma)
{ Ma=Ima->imx[i];}
me=Ima->imx[0];
for(i=0;i<Ima->size;i++)
{ Ima->imx[i];
if(Ima->imx[i]<me)
{ me=Ima->imx[i];}
den=Ma-me;
fac=255/den;
for(i=0;i<Ima->size;i++)
{ I->imx[i]=(fac*(Ima->imx[i]-me));}
gcFreeImg(Ima);
return (I);
gcGetImgBmp()
Funcion que lee un archivo bmp y lo coloca en memoria para su Proc.
*/
{ gcIMG *img;
FILE *file;
int i,j,a,ar;
if ( (file = fopen(ruta,"rb"))==NULL )
exit(1);
exit (1);
if ( (img->id[0]!='B')||(img->id[1]!='M') )
exit (1);
exit (1);
exit (1);
rewind(file);
fread(img->head,1078,1,file);
// Lectura de la imagen
a=img->ancho;
img->imx[i*a+j]=(float)fgetc(file);
fclose(file);
return img;
gcPutImgBmp()
*/
{ FILE *file;
int aux,zero=0,i,j,offset,Newancho;
exit(1);
offset=img->ancho%4;
// Checar el encabezado
fwrite(img->head,1078,1,file);
// Generar encabezado:
else {
fwrite(&aux,4,1,file); // Escribe
File Size
fwrite(&zero,4,1,file); // Escribe
Word Reserved
aux=1078;
fwrite(&aux,4,1,file); // Escribe
Data Offset
// Image Header
aux=40;
fwrite(&aux,4,1,file); // Escribe
Header Size
aux=img->ancho;
fwrite(&aux,4,1,file); // Escribe
Width
aux=img->alto;
fwrite(&aux,4,1,file); // Escribe
Height
aux=1;
fwrite(&aux,2,1,file); // Escribe
Planes
aux=8;
fwrite(&aux,2,1,file); // Escribe
Bits p/pixel
aux=0;
fwrite(&aux,4,1,file); // Escribe
Compression
aux=(Newancho*img->alto);
fwrite(&aux,4,1,file); // Escribe
Bitmap Size
aux=0;
fwrite(&aux,4,1,file); // Escribe
HResolution
aux=256;
aux=0;
// Escritura de la paleta
aux=img->ancho;
for(i=0;i<img->alto;i++)
for(j=0;j<Newancho;j++)
{ if(j>aux-1) fputc(0,file);
fclose(file);
gcNewImg()
*/
gcIMG *img;
int i;
img->ancho = ancho;
img->alto = alto;
img->size = ancho*alto;
exit (1);
img->head = NULL;
return img;
gcfreeImg()
*/
{ free(img->head);
free(img->imx);
free(img);
}
Deteccin de Bordes Usando el Operador Matemtico Prewitt W: