lecture_24_revised

Lecture_24_revised - FILE*f = fopen(filename"r" if f!= NULL read off header line fscanf(f"%s" header 2 mp4img.cc 10:04 David

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1 · mp4img.cc · 2010-11-11 10:04 · David Nicol #include <stdio.h> #include <stdlib.h> struct ppmImg { char type[4]; int rows, cols, max_val; int *r, *g, *b; }; typedef struct ppmImg PPM; PPM *NewImage( int c, int r, int m) { PPM *im; im = (PPM *)malloc( sizeof (PPM)); if ( im != NULL ) { strcpy(im->type, "PS3" ); im->rows = r; im->cols = c; im->max_val = m; /* allocate space for the color maps */ im->r = ( int *)malloc( c*r* sizeof ( int ) ); im->g = ( int *)malloc( c*r* sizeof ( int ) ); im->b = ( int *)malloc( c*r* sizeof ( int ) ); /* ensure we got the needed space */ if ( im->r == NULL || im->g == NULL || im->b == NULL ) { exit(-1); } } else exit(-1); return im; } void FreeImageMemory( PPM *im ) { if ( im != NULL ) { if ( im->r ) free(im->r); if ( im->g ) free(im->g); if ( im->b ) free(im->b); free(im); } return ; } PPM *LoadImage( const char *filename ) { PPM *im = NULL ; char header[80]; int r,c,m; int ri, ci, pix;
Background image of page 8
Background image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: FILE *f = fopen(filename, "r" ); if ( f != NULL ) { /* read off header line */ fscanf(f, "%s" , header); 2 · mp4img.cc · 2010-11-11 10:04 · David Nicol /* get image dimensions */ fscanf(f, "%d %d %d" , &c, &r, &m); /* get image structure */ im = NewImage( c, r, m); /* now we read off r*c pixels in row major order */ for (ri=0; ri<r; ri++) for (ci=0; ci<c; ci++) { /* compute 1D address in 2D space */ pix = ri*c+ci; fscanf(f, "%d %d %d" , &im->r[pix], &im->g[pix], &im->b[pix] ); } } else { printf( "Filename %s cannot be opened for this application\n" , filename); exit(-1); } return im; } int main() { PPM *image = NULL ; image = LoadImage( "my-image.ppm" ); /* process DetectContours(image); */ FreeImageMemory( image ); }...
View Full Document

This note was uploaded on 08/29/2011 for the course ECE 265 taught by Professor Kosbar during the Fall '09 term at Missouri S&T.

Page1 / 9

Lecture_24_revised - FILE*f = fopen(filename"r" if f!= NULL read off header line fscanf(f"%s" header 2 mp4img.cc 10:04 David

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online