Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Programa en C que maneje un fichero .jag (16x16 valores entre 0 y 255) */
- #include <stdio.h>
- #include <stdlib.h>
- #define FIL 16 // filas
- #define COL 16 // columnas
- /* Lee y almacena la imagen en una matriz de enteros a partir de
- un fichero en formato jag cuyo nombre proporciona el usuario. */
- // Define la función LeeImagen (Apartado a)
- int LeeImagen( int img[FIL][COL] ){
- FILE *f;
- int i, j;
- char nombre_f[80];
- gets(nombre_f); // nombre del fichero a leer
- f=fopen(nombre_f,"r");
- if(f==NULL) return -1;
- else{
- for( i=0 ; i<FIL ; i++ )
- for( j=0 ; j<COL ; j++ )
- fscanf(f,"%d",&img[i][j]);
- fclose(f);
- return 0;
- }
- }
- /* Devuelve el valor mínimo y el valor máximo (por referencia)
- entre los valores de los pixeles de la imagen. */
- // Define la función MinMaxImagen (Apartado b)
- void MinMaxImagen( int img[FIL][COL], int *min, int *max){
- int i, j, minimo, maximo;
- minimo=img[0][0];
- maximo=img[0][0];
- for( i=0 ; i<FIL ; i++ )
- for( j=0 ; j<COL ; j++ ){
- if( img[i][j]<minimo) minimo=img[i][j];
- if( img[i][j]>maximo) maximo=img[i][j];
- }
- *min=minimo;
- *max=maximo;
- }
- /* Aplica la transformación:
- Pixel transformado=( (Valor original - minimo)*255 ) / ( max-min ) */
- // Define la función TransformaImagen (Apartado c)
- void TransformaImagen( int img[FIL][COL], int min, int max ){
- int i, j;
- for( i=0 ; i<FIL ; i++ )
- for( j=0 ; j<COL ; j++ )
- img[i][j]=((img[i][j]-min)*255)/(max-min);
- }
- int main(){
- int img[FIL][COL];
- int error, min, max;
- if (LeeImagen(img) == -1){
- printf("Error abriendo fichero imagen\n");
- return -1;
- }
- MinMaxImagen(img, &min, &max);
- TransformaImagen(img, min, max);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement