ftp.nice.ch/pub/next/graphics/bitmap/dips.1.00.s.tar.gz#/DIPS/_dips/Cntrl.c

This is Cntrl.c in view mode; [Download] [Up]

#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<sys/time.h>
#include	"Cntrl.h"
#include	"Mask.h"
#include	"HipsImage.h"

main(int argc, char *argv)
{

	int		op;
	int		l, h;
	char		*mfile;
	hipsImage	*org_image;
	hipsImage	*trx_image;
	mask		*m;
	struct timeval	t1,t2;
	struct timezone	tz1,tz2;
	double		s;
	double		ts1, ts2;


  if(!checkInput(argc, argv, &op, &mfile, &l, &h))
    exit(1);

  m = (mask *)malloc(sizeof(mask));

  org_image = (hipsImage *)malloc(sizeof(hipsImage)); 
  if(!openImage(org_image)) {
    fprintf(stderr,"Problem opening image\n");
    exit(1);
  }
  trx_image = copyImage(org_image);

  switch(op) {
    case CONVOLVE:
      if(!openMask(mfile, m)) {
        fprintf(stderr,"Problem opening mask %f\n",mfile);
        exit(1);
      }
      gettimeofday(&t1,&tz1);
      convolveImage(trx_image, m);
      gettimeofday(&t2,&tz2);

      /* seconds */
      ts1 = ((double)t1.tv_usec)/1000000.0 + (double)t1.tv_sec;
      ts2 = ((double)t2.tv_usec)/1000000.0 + (double)t2.tv_sec;

      s = ts2 - ts1;
      fprintf(stderr,"Seconds: %10.5lf\n",s);
      break;
    case INVERT:
      invertImage(trx_image);
      break;
    case THRESH:
      threshImage(trx_image,l,h);
      break;
  }

  if(!saveImage(trx_image)) {
    fprintf(stderr,"Problem writing output image \n");
    exit(1);
  }

  exit(0);
}


int checkInput(int argc, char *argv[], int *op, char **mfile, int *l, int *h)
{

  switch(argc) {
    case 4:
      if(!strcmp(argv[1],"-c")) {
        *op = CONVOLVE;
        if(!strcmp(argv[2],"-m")) {
          *mfile = (char *)malloc((strlen(argv[3])+1)*sizeof(char));
          strcpy(*mfile,argv[3]);
        }
        else {
          usage();
          return 0;
        }
      }
      else if(!strcmp(argv[1],"-t")) {
        *op = THRESH;
        *l = atoi(argv[2]);
        *h = atoi(argv[3]);
      }
      else {
        usage();
        return 0;
      }
      break;
    case 2:
      if(!strcmp(argv[1],"-i"))
        *op = INVERT;
      else {
        usage();
        return 0;
      }
      break;
    default:
      usage();
      return 0;
      break;
  }
  return 1;
}


usage()
{
  fprintf(stderr,"\n");
  fprintf(stderr,"Usage: dips [-i | -c -m mask | -t low high] < inImage.hips > outImage.hips\n");
  fprintf(stderr,"Where options are:\n");
  fprintf(stderr,"  -i invert operation\n");
  fprintf(stderr,"  -t threshold operation, low, high values needed\n");
  fprintf(stderr,"  -c convolve operation, the -m flag must be present\n");
  fprintf(stderr,"  -m mask, mask used for convolution\n");
  fprintf(stderr,"Examples:\n");
  fprintf(stderr,"  dips -c -m mask_file < inImage.hips > outImage.hips\n");
  fprintf(stderr,"  dips -i < inImage.hips > outImage.hips\n");
  fprintf(stderr,"  dips -t low high < inImage.hips > outImage.hips\n");
  fprintf(stderr,"If no inImage, outImage are not specified, dips\n");
  fprintf(stderr,"reads/writes to stdin/stdout\n");
  fprintf(stderr,"\n");
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.