How to read images with argc & argv?

Hi guys, this is my piece of codes using microsoft platform.

/* {{{ Copyright etc. */


  SUSAN Version 2l by Stephen Smith
  Oxford Centre for Functional Magnetic Resonance Imaging of the Brain,
  Department of Clinical Neurology, Oxford University, Oxford, UK
  (Previously in Computer Vision and Image Processing Group - now
  Computer Vision and Electro Optics Group - DERA Chertsey, UK)
  Email:    [email][/email]

  (C) Crown Copyright (1995-1999), Defence Evaluation and Research Agency,
  Farnborough, Hampshire, GU14 6TD, UK
  DERA WWW site:
  DERA Computer Vision and Electro Optics Group WWW site:
  DERA Computer Vision and Electro Optics Group point of contact:
  Dr. John Savage, [email][/email], +44 1344 633203

  A UK patent has been granted: "Method for digitally processing
  images to determine the position of edges and/or corners therein for
  guidance of unmanned vehicle", UK Patent 2272285. Proprietor:
  Secretary of State for Defence, UK. 15 January 1997

  This code is issued for research purposes only and remains the
  property of the UK Secretary of State for Defence. This code must
  not be passed on without this header information being kept
  intact. This code must not be sold.


/* }}} */
/* {{{ defines, includes and typedefs */

/* ********** Optional settings */

#ifndef PPC
typedef int        TOTAL_TYPE; /* this is faster for "int" but should be "float" for large d masks */
typedef float      TOTAL_TYPE; /* for my PowerPC accelerator only */

/*#define FOPENB*/           /* uncomment if using djgpp gnu C for DOS or certain Win95 compilers */
#define SEVEN_SUPP           /* size for non-max corner suppression; SEVEN_SUPP or FIVE_SUPP */
#define MAX_CORNERS   15000  /* max corners per frame */

/* ********** Leave the rest - but you may need to remove one or both of sys/file.h and malloc.h lines */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include <sys/file.h>    /* may want to remove this line */
//#include <malloc.h>      /* may want to remove this line */
#define  exit_error(IFB,IFC) { fprintf(stderr,IFB,IFC); exit(0); }
#define  FTOI(a) ( (a) < 0 ? ((int)(a-0.5)) : ((int)(a+0.5)) )
typedef  unsigned char uchar;
typedef  struct {int x,y,info, dx, dy, I;} CORNER_LIST[MAX_CORNERS];

int getint(fd)
  FILE *fd;
  int c, i;
  char dummy[10000];

  c = getc(fd);
  while (1) /* find next integer */
    if (c=='#')    /* if we're at a comment, read to end of line */
    if (c==EOF)
      exit_error("Image %s not binary PGM.
    if (c>='0' && c<='9')
      break;   /* found what we were looking for */
    c = getc(fd);

  /* we're at the start of a number, continue until we hit a non-number */
  i = 0;
  while (1) {
    i = (i*10) + (c - '0');
    c = getc(fd);
    if (c==EOF) return (i);
    if (c<'0' || c>'9') break;

  return (i);

/* }}} */

void get_image(filename,in,x_size,y_size)
  char           filename[200];
  unsigned char  **in;
  int            *x_size, *y_size;
FILE  *fd;
char header [100];
int  tmp;

#ifdef FOPENB
  if ((fd=fopen(filename,"rb")) == NULL)
  if ((fd=fopen(filename,"r")) == NULL)
    exit_error("Can't input image %s.

  /* {{{ read header */

  if(!(header[0]=='P' && header[1]=='5'))
    exit_error("Image %s does not have binary PGM header.

  *x_size = getint(fd);
  *y_size = getint(fd);
  tmp = getint(fd);

/* }}} */

  *in = (uchar *) malloc(*x_size * *y_size);

  if (fread(*in,1,*x_size * *y_size,fd) == 0)
    exit_error("Image %s is wrong size.


/* }}} */
/* {{{ put_image(filename,in,x_size,y_size) */

  char filename [100],
  int  x_size,
FILE  *fd;

#ifdef FOPENB
  if ((fd=fopen(filename,"wb")) == NULL) 
  if ((fd=fopen(filename,"w")) == NULL) 
    exit_error("Can't output image%s.

  fprintf(fd,"%d %d
  if (fwrite(in,x_size*y_size,1,fd) != 1)
    exit_error("Can't write image %s.


main(argc, argv)
  int   argc;
  char  *argv ];
/* {{{ vars */

FILE   *ofp;
char   filename [80],
uchar  *in, *bp, *mid;
float  dt=4.0;
int    *r,
       mode = 0, i,
       x_size, y_size;
CORNER_LIST corner_list;




/* }}} */

/* }}} */


/* }}} */

Sorry i just cannot include the full program in because it might be too complicated or too long. The main modification will be on get_image and put_image subroutines.

So, how can i modified it to read the image files(>50) from a directory and write the processed images into another directory?

Thank you.

You might want to just read in a text file which has a list of all the files you want to process then read each file in line by line process it and write it backout.
That shouldn’t be too hard. If you can’t do that I would probably suggest doing some tutorials or something before diving into image processing stuff.

Sorry if my thread sounds amateur to you because i am a beginner.
I can do this for normal text file but it just cannot happen when comes to binary file.
I can read and write for one image file as shown on above. Can you educate me on how to make it perhaps a loop to continuously read and write more image files using argv and argc functions?

Thank you.

just curious, why do you want to use argc and argv?

I have fairly limited experience with argc and argv ( I have only used it with text files) but cant you set argc equal to the number of files you want to read in and then just enter all the file names on the command line when you run the program. You should be able to refer to the files as argv* where i is the posistion it was read in from ex. 1 would be first, 2 would be second etc.

You could then write a for loop, put all the code you want to execute on the picture inside of the loop and then just increment i to do the same for the next picture.

I may have not understood what you asked or my logic may be flawed for some other reason but I think this would work.*