float
) values to range
\([0, 1]\)
prior to output is what is required.
main()
funcrtion can look something like this
(with two filters, dx and dy for vertical and horizontal edges,
e.g., see this page for more info):
int main(int argc,char **argv)
{
PGM *gimg=NULL;
PGM *ndximg=NULL, *ndyimg=NULL;
PGM *dximg=NULL, *dyimg=NULL;
FLTR *gxp=make_filter(0), *gyp=make_filter(1);
// allocte image of given size
gimg = pgm_read("mandrill.pgm");
// convolve
dximg = pgm_conv(gimg,gxp);
dyimg = pgm_conv(gimg,gyp);
// copy edge image and normalize, for visualization purposes
ndximg = pgm_copy(dximg);
pgm_normalize(ndximg);
pgm_write(ndximg,"ndxgrey.pgm");
ndyimg = pgm_copy(dyimg);
pgm_normalize(ndyimg);
pgm_write(ndyimg,"ndygrey.pgm");
// output to file
pgm_write(dximg,"dxgrey.pgm");
pgm_write(dyimg,"dygrey.pgm");
// free image by sending pointer to pointer to ppm_free function
pgm_free(&dximg);
pgm_free(&dyimg);
pgm_free(&gimg);
free_filter(&gxp);
free_filter(&gyp);
return 0;
}
main.c
here is a
Makefile
that you can use to try to compile the project:
CC = gcc
INCLUDE = -I.
CFLAGS = -g
LDFLAGS = -L. -L/usr/lib
LDLIBS = -lc -lm
.c.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<
OBJECTS = \
pgm.o \
arrays.o \
filters.o
all: main
main: main.o main.c
$(CC) $(CFLAGS) $(INCLUDE) -o $@ $@.o $(OBJECTS) $(LDFLAGS) $(LDLIBS)
main.o: main.c
clean:
rm -f *.o
rm -rf main
Note that each line underneath the targets is indented by a tab, not just
spaces, this is important!
tar.gz
archive of your asg##/ directory, including:
README
file containing
Makefile
.h
headers and .c
source)
make clean
before tar
)
handin
notes