lundi 20 avril 2015

Image/IO Loop over image (C)

I am attempting to convert a PPM image to PGM and loop through the image at each pixel do double avg etc...

#include <stdio.h>
#include "image-io.h"
int main(int agrc, char **argv)
{
    int i, j;
    if (agrc != 3) {
        fprintf(stderr, "Usage: %s infile outline\n", argv[0]);
        fprintf(stderr, "Reads PGM or PPM from infile,"
                "writes identical image to outline \n");
        return EXIT_FAILURE;
    }
    pm_init(argv[0], 0);
    struct image *img = read_image(argv[1]);
    fprintf(stderr, "input image is %dx%d, depth=%d, maxval=%d\n",
            img->pam.height, img->pam.width,
            img->pam.depth, (int) img->pam.maxval);
    img->pam.format = RPGM_FORMAT;
    img->pam.depth  = 1;
    for ( i  = 0 ; i < img->pam.height; i++) {
        for ( j = 0 ; j < img->pam.width; j++) {
            double avg = (img->r[i][j] +img->g[i][j] + img->b[i][j]) /3.0;
            img->g[i][j] = (int) (0.5 + avg);
        }
    }




    write_image(argv[2], img);
    free_image(img);
    return EXIT_SUCCESS;
}

I am having issue looping over the image

Aucun commentaire:

Enregistrer un commentaire