Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-18-2007, 10:10 AM
tommy_chai tommy_chai is offline
Newbie
 
Join Date: Oct 2007
Posts: 16
Rep Power: 5
tommy_chai is on a distinguished road
Default How to read images with argc & argv?

Hi all,

i have using argc and argv to read an image as below:
Code:
int main(argc,argv)
int argc
;
char *argv[];
{
:
:
:
	for(total = 0; total<NUM; total ++){
		read_data_grey2(argv[1],gry2); /*argv[1]->filename gry2-                                                                     >array for output data*/
                                              :
                                              :
             }
}
This is the coding i use to read one image.
How can i modify these codes in order to read more images?
Any idea will be appreciated. Thanks.

Last edited by tommy_chai; 10-29-2007 at 10:36 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 10-18-2007, 11:48 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

argc usually contains the amount of parameters passed to the program.
argv contains all the strings passed to the program, and usually the first parameter is the program itself. If I get it right, you want to read multiple images, and the images you will read are those passed to the program (filenames.) If so, then you can combine argc and argv. Use the value in argc for looping through the array argv.
Code:
#include <stdio.h>

int main(int argc, char *argv[])
{
        int i;

        printf("Amount of strings passed: %d\n", argc);
        printf("Printing the passed strings...\n");
        for(i = 0; i < argc; i++)
                printf(" #%d: %s\n", i+1, argv[i]);

        return 0;
}
Example:
Code:
$ ./test Hello, World!
Amount of strings passed: 3
Printing the passed strings...
 #1: ./test
 #2: Hello,
 #3: World!
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-18-2007, 12:22 PM
tommy_chai tommy_chai is offline
Newbie
 
Join Date: Oct 2007
Posts: 16
Rep Power: 5
tommy_chai is on a distinguished road
Default

Thanks for your reply. Can i know how can we open 100 image files let say image1.pgm image2.pgm......... by using argv & argc automatically?
Currently i am using a method to automatically set the directory to open a txt file contains all images' filename inside. I think of trying to do this by using argv & argc commands. My problem is, even a loop is used, i still need to type all the 100 images filename while executing my program so that argv[1]....argv[100] can be used to open those images?
Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-18-2007, 12:38 PM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Look at my source again. Instead of printing each of the filenames, you could simply open each of the files, using the filename. If you want to, you could save all the streams in an array, which you could use later.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-29-2007, 10:32 AM
tommy_chai tommy_chai is offline
Newbie
 
Join Date: Oct 2007
Posts: 16
Rep Power: 5
tommy_chai is on a distinguished road
Default

Do u mind to educate me if i want to use argv n argc to read and write image files automatically?
This is piece of the program. Sorry for not including all because it is just too long and complicated from my view.

Code:
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:    steve@fmrib.ox.ac.uk
  WWW:      http://www.fmrib.ox.ac.uk/~steve

  (C) Crown Copyright (1995-1999), Defence Evaluation and Research Agency,
  Farnborough, Hampshire, GU14 6TD, UK
  DERA WWW site:
  DERA
  DERA Computer Vision and Electro Optics Group WWW site:
  http://www.dera.gov.uk/imageprocessi...roup_home.html
  DERA Computer Vision and Electro Optics Group point of contact:
  Dr. John Savage, jtsavage@dera.gov.uk, +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 */
#else
typedef float      TOTAL_TYPE; /* for my PowerPC accelerator only */
#endif

/*#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 */
      fgets(dummy,9000,fd);
    if (c==EOF)
      exit_error("Image %s not binary PGM.\n","is");
    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)
#else
  if ((fd=fopen(filename,"r")) == NULL)
#endif
    exit_error("Can't input image %s.\n",filename);

  /* {{{ read header */

  header[0]=fgetc(fd);
  header[1]=fgetc(fd);
  if(!(header[0]=='P' && header[1]=='5'))
    exit_error("Image %s does not have binary PGM header.\n",filename);

  *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.\n",filename);

  fclose(fd);
}

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

put_image(filename,in,x_size,y_size)
  char filename [100],
       *in;
  int  x_size,
       y_size;
{
FILE  *fd;

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

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

  fclose(fd);
}

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

FILE   *ofp;
char   filename [80],
       *tcp;
uchar  *in, *bp, *mid;
float  dt=4.0;
int    *r,
       argindex=3,
       bt=13,
       principle=0,
       thin_post_proc=1,
       three_by_three=0,
       drawing_mode=0,
       susan_quick=0,
       max_no_corners=1850,
       max_no_edges=2650,
       mode = 0, i,
       x_size, y_size;
CORNER_LIST corner_list;

   get_image(argv[1],&in,&x_size,&y_size);

        susan_corners(in,r,bp,max_no_corners,corner_list,x_size,y_size);
        corner_draw(in,corner_list,x_size,drawing_mode);
      }

      break;

/* }}} */
  }    

/* }}} */

  put_image(argv[2],in,x_size,y_size);
}

/* }}} */
Mind to teach me how to modify the get_image and put_image to read and write processed image files (>50)?

Thank you for helping. Appreciated.

Last edited by tommy_chai; 10-29-2007 at 10:38 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Resize Images And Maintain Original Sharpness AfTriX Photoshop Tutorials 7 04-20-2007 10:55 AM
Preload Images xtraze Tutorials 3 01-07-2007 03:16 AM
CSS vs HTML images John JavaScript and CSS 1 12-23-2006 09:02 PM
Optimizing Images DevilsCharm Search Engine Optimization 3 08-20-2006 10:36 AM


All times are GMT -5. The time now is 03:55 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads