/*---------------------------------------------------------------------------*/ /* Program: zsplit.c */ /* */ /* Purpose: This program takes a 3D KUIM image and splits it into */ /* a collection of 2D images. This operation is the opposite */ /* of imzcat. */ /* */ /* Author: John Gauch */ /* */ /* Date: March 2, 1995 */ /* */ /* Note: Copyright (C) The University of Kansas, 1995 */ /*---------------------------------------------------------------------------*/ #include /*---------------------------------------------------------------------------*/ /* Purpose: This is the main program. */ /*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { /* Image variables */ char Name1[50]; char Name2[50]; char Name3[50]; IM_TYPE *Image1; IM_TYPE *Image2; BYTE_TYPE ***Data1; int PixType, Xdim, Ydim, Zdim, DimCnt; unsigned char Red[nCMAP], Green[nCMAP], Blue[nCMAP]; /* Program variables */ int Debug = FALSE; int JPEG = FALSE; int Number = 0; int i = 0, z; /* Interpret program options */ printf("ZSPLIT Program - KUIM Version 1.0\n\n"); while ((++i < argc) && (argv[i][0] == '-')) switch (argv[i][1]) { case 'n': if (sscanf(argv[++i], "%d", &Number) == 0) Error("Could not get integer argument"); break; case 'd': Debug = TRUE; break; case 'j': JPEG = TRUE; break; default: Error("Invalid option encountered"); break; } /* Check number of file names */ if (argc - i != 2) { fprintf(stderr, "Usage: zsplit [options] infile outprefix\n"); fprintf(stderr, " [-d] Print debugging information\n"); fprintf(stderr, " [-n #] Initial suffix value (0)\n"); fprintf(stderr, " [-j] Output JPEG format\n"); exit(1); } /* Get image file names from argument list */ if (sscanf(argv[i++], "%s", Name1) == 0) Error("Could not get input file name"); if (sscanf(argv[i++], "%s", Name2) == 0) Error("Could not get output file prefix"); /* Open input image */ Image1 = im_open(Name1, &PixType, &Xdim, &Ydim, &Zdim, &DimCnt); if (DimCnt != 3) Error("Can only process 3D images"); /* Handle color images */ if (PixType == COLOR || PixType == PSEUDO || PixType == JPEG_RGB) { /* Read input image */ Data1 = (PSEUDO_TYPE ***) im_alloc3D(Image1, PSEUDO); im_read(Image1, PSEUDO, (char *) &(Data1[0][0][0])); im_get_cmap(Image1, Red, Green, Blue); /* Loop creating and writing output images */ for (z = 0; z < Zdim; z++) { sprintf(Name3, "%s%02d", Name2, Number + z); if (Debug == TRUE) printf("Creating %s\n", Name3); if (JPEG == TRUE) Image2 = im_create(Name3, JPEG_RGB, Xdim, Ydim, 1); else Image2 = im_create(Name3, PixType, Xdim, Ydim, 1); im_put_cmap(Image2, Red, Green, Blue); im_write(Image2, PSEUDO, (char *) &(Data1[z][0][0])); } } /* Handle greyscale images */ else { /* Read input image */ Data1 = (BYTE_TYPE ***) im_alloc3D(Image1, BYTE); im_read(Image1, BYTE, (char *) &(Data1[0][0][0])); /* Loop creating and writing output images */ for (z = 0; z < Zdim; z++) { sprintf(Name3, "%s%02d", Name2, Number + z); if (Debug == TRUE) printf("Creating %s\n", Name3); if (JPEG == TRUE) Image2 = im_create(Name3, JPEG_GRAY, Xdim, Ydim, 1); else Image2 = im_create(Name3, PixType, Xdim, Ydim, 1); im_write(Image2, BYTE, (char *) &(Data1[z][0][0])); } } /* Free buffer */ im_free3D((char ***) Data1); return (0); }