IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 633


Ignore:
Timestamp:
May 10, 2004, 10:20:42 AM (22 years ago)
Author:
harman
Message:

Added psAlloc alloc and free functions

Location:
trunk/psLib/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/Makefile

    r563 r633  
    33endif
    44
    5 TARGET = psStats.o libpsDataManip.a
     5TARGET = psImage.o psStats.o libpsDataManip.a
    66
    77all: $(TARGET)
     
    99include ../Makefile.Globals
    1010
    11 SRC_OBJS = 
     11SRC_OBJS =
    1212
    1313%.o: %.c
  • trunk/psLib/src/image/psImage.c

    r599 r633  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-07 02:56:52 $
     9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-10 20:20:42 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717/******************************************************************************/
    1818#include "psMemory.h"
     19#include "psError.h"
    1920#include "psArray.h"
     21#include "psImage.h"
    2022
    2123/******************************************************************************/
     
    5355/*****************************************************************************/
    5456
    55 psImage *psImageAlloc(int nx, int ny, psType type)
     57psImage *psImageAlloc(int nCols, int nRows, psType type)
    5658{
    5759    psImage *image = NULL;
    5860
    59     psImage = psAlloc(psImage);
    60     psImage->type = type;
    61     psImage->nx = nx;
    62     psImage->ny = ny;
    63     psImage->x0 = 0;
    64     psImage->y0 = 0;
    65     psImage->parent = NULL;
    66     psImage->nChildren = 0;
    67     psImage->children = NULL;
     61    image = psAlloc(sizeof(psImage));
     62    image->type = type;
     63    image->nCols = nCols;
     64    image->nRows = nRows;
     65    image->col0 = 0;
     66    image->row0 = 0;
     67    image->parent = NULL;
     68    image->nChildren = 0;
     69    image->children = NULL;
    6870
    6971    switch(type.type) {
    7072    case PS_TYPE_SHORT:
    71         image->rows.rows_si = psAlloc(nx*ny*sizeof(short));
     73        image->rows.rows_s = psAlloc(nCols*nRows*sizeof(short));
    7274        break;
    7375    case PS_TYPE_INT:
    74         image->rows.rows_i = psAlloc(nx*ny*sizeof(int));
     76        image->rows.rows_i = psAlloc(nCols*nRows*sizeof(int));
    7577        break;
    7678    case PS_TYPE_LONG:
    77         image->rows.rows_li = psAlloc(nx*ny*sizeof(long));
     79        image->rows.rows_l = psAlloc(nCols*nRows*sizeof(long));
    7880        break;
    7981    case PS_TYPE_USHORT:
    80         image->rows.rows_us = psAlloc(nx*ny*sizeof(unsigned short));
     82        image->rows.rows_us = psAlloc(nCols*nRows*sizeof(unsigned short));
    8183        break;
    8284    case PS_TYPE_UINT:
    83         image->rows.rows_ui = psAlloc(nx*ny*sizeof(unsigned int));
     85        image->rows.rows_ui = psAlloc(nCols*nRows*sizeof(unsigned int));
    8486        break;
    8587    case PS_TYPE_ULONG:
    86         image->rows.rows_ul = psAlloc(nx*ny*sizeof(unsigned long));
     88        image->rows.rows_ul = psAlloc(nCols*nRows*sizeof(unsigned long));
    8789        break;
    8890    case PS_TYPE_FLOAT:
    89         image->rows.rows_f = psAlloc(nx*ny*sizeof(float));
     91        image->rows.rows_f = psAlloc(nCols*nRows*sizeof(float));
    9092        break;
    9193    case PS_TYPE_DOUBLE:
    92         image->rows.rows_d = psAlloc(nx*ny*sizeof(double));
     94        image->rows.rows_d = psAlloc(nCols*nRows*sizeof(double));
    9395        break;
    9496    case PS_TYPE_COMPLEX:
    95         image->rows.rows_cf = psAlloc(nx*ny*sizeof(complex float));
    96         break;
    97     case PS_TYPE_OTHER:
    98         psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
     97        image->rows.rows_cf = psAlloc(nCols*nRows*sizeof(complex float));
    9998        break;
    10099    default:
    101         psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
     100        psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, type.type);
    102101    }
    103102
     103    return image;
     104}
    104105
     106void psImageFree(psImage *image)
     107{
     108    int i = 0;
     109    int nChildren = 0;
     110    psElemType imageType = 0;
     111    psImage *children = NULL;
     112
     113    if(image != NULL) {
     114        imageType = image->type.type;
     115        nChildren = image->nChildren;
     116        children = image->children;
     117
     118        switch(imageType) {
     119        case PS_TYPE_SHORT:
     120            psFree(image->rows.rows_s);
     121            break;
     122        case PS_TYPE_INT:
     123            psFree(image->rows.rows_i);
     124            break;
     125        case PS_TYPE_LONG:
     126            psFree(image->rows.rows_l);
     127            break;
     128        case PS_TYPE_USHORT:
     129            psFree(image->rows.rows_us);
     130            break;
     131        case PS_TYPE_UINT:
     132            psFree(image->rows.rows_ui);
     133            break;
     134        case PS_TYPE_ULONG:
     135            psFree(image->rows.rows_ul);
     136            break;
     137        case PS_TYPE_FLOAT:
     138            psFree(image->rows.rows_f);
     139            break;
     140        case PS_TYPE_DOUBLE:
     141            psFree(image->rows.rows_d);
     142            break;
     143        case PS_TYPE_COMPLEX:
     144            psFree(image->rows.rows_cf);
     145            break;
     146        case PS_TYPE_OTHER:
     147            psError(__func__, " : Line %d - Can't delete images of type PS_TYPE_OTHER\n", __LINE__);
     148            break;
     149        default:
     150            psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, imageType);
     151        }
     152
     153        for(i=0; i<nChildren; i++) {
     154            psImageFree(children);
     155        }
     156    }
    105157}
  • trunk/psLib/src/image/psImage.h

    r599 r633  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-07 02:56:52 $
     9 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-10 20:20:42 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636{
    3737    psType type;                    ///< Image data type and dimension.
    38     int nx, ny;                     ///< Size of image.
    39     int x0, y0;                     ///< Data region relative to parent.
     38    int nCols;                      ///< Number of rows in image
     39    int nRows;                      ///< Number of columns in image.
     40    int col0;                       ///< Row position relative to parent.
     41    int row0;                       ///< Column position relative to parent.
    4042    union {
    41         float **rows                ///< Pointers to floating point data (default).
    4243        short **rows_s;             ///< Pointers to short integer data.
    4344        int **rows_i;               ///< Pointers to integer data.
     
    4647        unsigned int **rows_ui;     ///< Pointers to unsigned integer data.
    4748        unsigned long **rows_ul;    ///< Pointers to unsigned long integer data.
    48         float **rows_f              ///< Pointers to floating point data.
    49         double **rows_d             ///< Pointers to double precision data.
    50         complex float **rows_cf     ///< Pointers to complex floating point data.
     49        float **rows_f;             ///< Pointers to floating point data.
     50        double **rows_d;            ///< Pointers to double precision data.
     51        complex float **rows_cf;    ///< Pointers to complex floating point data.
    5152    } rows;                         ///< Union for data types.
    5253    struct psImage *parent;         ///< Parent, if a subimage.
     
    6970 */
    7071psImage *psImageAlloc(
    71     int nx,     ///< Image width.
    72     int ny,     ///< Image height.
    73     psType type ///< Image data type.
     72    int nCols,  ///< Number of rows in image.
     73    int nRows,  ///< Number of columns in image.
     74    psType type ///< Type of data for image.
    7475);
    7576
     
    8485    psImage *out,           ///< Subimage to return, or NULL.
    8586    const psImage *image,   ///< Parent image.
    86     int nx,                 ///< Subimage width (<= image.nx - x0).
    87     int ny,                 ///< Subimage width (<= image.ny - y0).
    88     int x0,                 ///< Subimage x-offset (0 <= x0 < nx).
    89     int y0                  ///< Subimage y-offset (0 <= y0 < ny).
     87    int nCols,              ///< Subimage width (<= image.nCols - col0).
     88    int nRows,              ///< Subimage height (<= image.nRows - row0).
     89    int col0,               ///< Subimage col-offset (0 <= col0 < nCol).
     90    int row0                ///< Subimage row-offset (0 <= row0 < nCol).
    9091);
    9192
     
    9899 */
    99100void psImageFree(
    100     psImage *restrict image ///< free this image
     101    psImage *restrict image ///< Free psImage
    101102);
    102103
    103 
    104 
    105 // DOXYGEN COMMENTING FORMAT NOT YET FULLY IMPLEMENTED BEYOND THIS POINT
    106 
    107 
    108 
    109 /** Destroy the pixels of the specified image */
    110 psImage *
    111 psImageFreePixels(psImage *restrict image ///< Image whose pixels are to be freed
    112                  );
    113 
    114 /// Destroy the children of the specified image.  Returns number of children freed.
    115 int
    116 psImageFreeChildren(const psImage *image ///< free children of this image
    117                    );
    118 
    119 /// Create a copy of the specified image.
    120 psImage *
    121 psImageCopy(psImage *output,   ///< target structure for output image data
    122             const psImage *input ///< copy this image
    123            );
    124 
    125 /*** various image pixel extractions ***/
    126 
    127 /// Extract pixels from rectlinear region to a vector.
    128 psFloatArray *
    129 psImageSlice(psFloatArray *out,  ///< Vector to output, or NULL
    130              const psImage *input, ///< extract slice from this image
    131              int x,    ///< starting x coord of region to slice
    132              int y,    ///< starting y coord of region to slice
    133              int nx,    ///< width of region in x
    134              int ny,    ///< width of region in y
    135              int direction,  ///< direction of vector along slice
    136              const psStats *stats ///< defines statistics used to find output values
    137             );
    138 
    139 /// Extract pixels along a line to a vector.
    140 psFloatArray *
    141 psImageCut(psFloatArray *out,  ///< Vector to output, or NULL
    142            const psImage *input, ///< extract cut from this image
    143            float xs,    ///< starting x coord of cut
    144            float ys,    ///< starting y coord of cut
    145            float xe,    ///< ending x coord of cut
    146            float ye,    ///< ending y coord of cut
    147            float dw,    ///< width of cut
    148            const psStats *stats  ///< defines statistics used to find output values
    149           );
    150 
    151 /// Extract radial annulii data to a vector.
    152 psFloatArray *
    153 psImageRadialCut(psFloatArray *out, ///< Vector to output, or NULL
    154                  const psImage *input, ///< extract profile from this image
    155                  float x,   ///< center x coord of annulii
    156                  float y,   ///< center y coord of annulii
    157                  float radius,  ///< outer radius of annulii
    158                  float dr,  ///< radial step size of annulii
    159                  const psStats *stats ///< defines statistics used to find output values
    160                 );
    161 
    162 /* Contour is a high-level function */
    163 #if 0
    164 /// Extract a 2-d contour from an image at the given threshold.
    165 psFloatArray *
    166 psImageContour(psFloatArray *out, ///< Vector to output, or NULL
    167                const psImage *input,  ///< create contour for this image
    168                float threshold, ///< contour image at this threshold
    169                int binning  ///< bin image by this value for contour calculation
    170               );
    171104#endif
    172 
    173 /*** various image geometry manipulation ***/
    174 /// Rebin image to new scale.
    175 psImage *
    176 psImageRebin(psImage *out,  ///< Image to output, or NULL
    177              const psImage *input, ///< rebin this image
    178              float scale,   ///< rebinning scale: doutput = scale*dinput
    179              const psStats *stats ///< defines statistics used to find output values
    180             );
    181 
    182 /// Rotate image by given angle.
    183 psImage *
    184 psImageRotate(psImage *out,  ///< Image to output, or NULL
    185               const psImage *input, ///< rotate this image
    186               float angle  ///< rotate by this amount anti-clockwise (degrees)
    187              );
    188 
    189 /// Shift image by an arbitrary number of pixels in either direction.
    190 /// Drop edge pixels, and set newly exposed pixels to 'exposed'.
    191 psImage *
    192 psImageShift(psImage *out,  ///< Image to output, or NULL
    193              const psImage *input, ///< shift this image
    194              float dx,   ///< shift by this amount in x
    195              float dy,   ///< shift by this amount in y
    196              float exposed  ///< set exposed pixels to this value
    197             );
    198 
    199 /// Roll image by an integer number of pixels in either direction.
    200 /// Edge pixels wrap to the other side (no values are lost).
    201 psImage *
    202 psImageRoll(psImage *out,  ///< Image to output, or NULL
    203             const psImage *input, ///< roll this image
    204             int dx,    ///< roll this amount in x
    205             int dy   ///< roll this amount in y
    206            );
    207 
    208 /// Determine statistics for image (or subimage).
    209 psStats *
    210 psImageGetStats(const psImage *input,  ///< image (or subimage) to calculate stats
    211                 psStats *stats  ///< defines statistics to be calculated & target
    212                );
    213 
    214 /// Construct a histogram from an image (or subimage).
    215 psHistogram *
    216 psImageHistogram(psHistogram *hist, ///< input histogram description & target
    217                  const psImage *input ///< determine histogram of this image
    218                 );
    219 
    220 /// Fit a 2-D polynomial surface to an image.
    221 psPolynomial2D *
    222 psImageFitPolynomial(const psImage *input, ///< image to fit
    223                      psPolynomial2D *coeffs ///< coefficient structure carries in desired terms & target
    224                     );
    225 
    226 /// Evaluate a 2-D polynomial surface to image pixels.
    227 int
    228 psImageEvalPolynomial(const psImage *input, ///< image to fit
    229                       const psPolynomial2D *coeffs ///< coefficient structure carries in desired terms
    230                      );
    231 
    232 /*** image input/output routines ***/
    233 /// Read an image or subimage from a named file.
    234 psImage *
    235 psImageReadSection(psImage *output,  ///< place data in this structure for output
    236                    int x,   ///< starting x coord of region
    237                    int y,   ///< starting y coord of region
    238                    int nx,   ///< x size of region (-1 for full range)
    239                    int ny,   ///< y size of region (-1 for full range)
    240                    int z,   ///< plane of interest
    241                    const char *extname, ///< MEF extension name ("PHU" for primary header)
    242                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    243                    const char *filename ///< file to read data from
    244                   );
    245 
    246 /// Read an image or subimage from file descriptor.
    247 psImage *
    248 psImageFReadSection(psImage *output, ///< place data in this structure for output
    249                     int x,  ///< starting x coord of region
    250                     int y,  ///< starting y coord of region
    251                     int nx,  ///< x size of region (-1 for full range)
    252                     int ny,  ///< y size of region (-1 for full range)
    253                     int z,  ///< plane of interest
    254                     const char *extname, ///< MEF extension name ("PHU" for primary header)
    255                     int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    256                     FILE *f  ///< file descriptor to read data from
    257                    );
    258 
    259 /// Write an image section to named file (which may exist).
    260 psImage *
    261 psImageWriteSection(psImage *input,    ///< image to write out
    262                     int x,   ///< starting x coord of region
    263                     int y,   ///< starting y coord of region
    264                     int z,   ///< plane of interest
    265                     const char *extname, ///< MEF extension name ("PHU" for primary header)
    266                     int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    267                     const char *filename ///< file to write data to
    268                    );
    269 
    270 /// Write an image section to named file (which may exist).
    271 psImage *
    272 psImageFWriteSection(psImage *input, ///< image to write out
    273                      int x,   ///< starting x coord of region
    274                      int y,   ///< starting y coord of region
    275                      int z,   ///< plane of interest
    276                      const char *extname, ///< MEF extension name
    277                      int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    278                      FILE *f  ///< file descriptor to write data to
    279                     );
    280 
    281 /// Read only header from image file.
    282 psMetadata *
    283 psImageReadHeader(psMetadata *output, ///< read data to this structure
    284                   const char *extname,  ///< MEF extension name ("PHU" for primary header)
    285                   int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    286                   const char *filename ///< file to read from
    287                  );
    288 
    289 /// Read only header from image file descriptor.
    290 psMetadata *
    291 psImageFReadHeader(psMetadata *output, ///< read data to this structure
    292                    const char *extname, ///< MEF extension name ("PHU" for primary header)
    293                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    294                    FILE *f  ///< file descriptor to read from
    295                   );
    296 
    297 /*** basic pixel manipulations ***/
    298 /// Clip image values outside of range to given values.  Return number of clipped pixels.
    299 int
    300 psImageClip(psImage *input,   ///< clip this image
    301             float min,   ///< clip pixels with values < min
    302             float vmin,   ///< set min-clipped pixels to vmin
    303             float max,   ///< clip pixels with values > max
    304             float vmax   ///< set max-clipped pixels to vmax
    305            );
    306 
    307 /// Clip NaN image pixels to given value.  Return number of clipped pixels.
    308 int
    309 psImageClipNaN(psImage *input,  ///< clip this image & target
    310                float value  ///< set nan pixels to this value
    311               );
    312 
    313 /// Overlay subregion of image with another image.  Return number of pixels replaced.
    314 int
    315 psImageOverlaySection(psImage *image, ///< input image & target
    316                       const psImage *overlay, ///< image to overlay
    317                       int x0,  ///< x offset of overlay subimage
    318                       int y0,  ///< y offset of overlay subimage
    319                       const char *op ///< overlay operation
    320                      );
    321 
    322 /* \} */ // End of AstroGroup Functions
    323 
    324 # endif
    325 /* image overlay operations
    326     PS_OVERLAY_EQUALS   = '=',
    327     PS_OVERLAY_ADD      = '+',
    328     PS_OVERLAY_SUBTRACT = '-',
    329     PS_OVERLAY_MULTIPLY = '*',
    330     PS_OVERLAY_DIVIDE   = '/',
    331 */
  • trunk/psLib/src/mathtypes/psImage.c

    r599 r633  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-07 02:56:52 $
     9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-10 20:20:42 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717/******************************************************************************/
    1818#include "psMemory.h"
     19#include "psError.h"
    1920#include "psArray.h"
     21#include "psImage.h"
    2022
    2123/******************************************************************************/
     
    5355/*****************************************************************************/
    5456
    55 psImage *psImageAlloc(int nx, int ny, psType type)
     57psImage *psImageAlloc(int nCols, int nRows, psType type)
    5658{
    5759    psImage *image = NULL;
    5860
    59     psImage = psAlloc(psImage);
    60     psImage->type = type;
    61     psImage->nx = nx;
    62     psImage->ny = ny;
    63     psImage->x0 = 0;
    64     psImage->y0 = 0;
    65     psImage->parent = NULL;
    66     psImage->nChildren = 0;
    67     psImage->children = NULL;
     61    image = psAlloc(sizeof(psImage));
     62    image->type = type;
     63    image->nCols = nCols;
     64    image->nRows = nRows;
     65    image->col0 = 0;
     66    image->row0 = 0;
     67    image->parent = NULL;
     68    image->nChildren = 0;
     69    image->children = NULL;
    6870
    6971    switch(type.type) {
    7072    case PS_TYPE_SHORT:
    71         image->rows.rows_si = psAlloc(nx*ny*sizeof(short));
     73        image->rows.rows_s = psAlloc(nCols*nRows*sizeof(short));
    7274        break;
    7375    case PS_TYPE_INT:
    74         image->rows.rows_i = psAlloc(nx*ny*sizeof(int));
     76        image->rows.rows_i = psAlloc(nCols*nRows*sizeof(int));
    7577        break;
    7678    case PS_TYPE_LONG:
    77         image->rows.rows_li = psAlloc(nx*ny*sizeof(long));
     79        image->rows.rows_l = psAlloc(nCols*nRows*sizeof(long));
    7880        break;
    7981    case PS_TYPE_USHORT:
    80         image->rows.rows_us = psAlloc(nx*ny*sizeof(unsigned short));
     82        image->rows.rows_us = psAlloc(nCols*nRows*sizeof(unsigned short));
    8183        break;
    8284    case PS_TYPE_UINT:
    83         image->rows.rows_ui = psAlloc(nx*ny*sizeof(unsigned int));
     85        image->rows.rows_ui = psAlloc(nCols*nRows*sizeof(unsigned int));
    8486        break;
    8587    case PS_TYPE_ULONG:
    86         image->rows.rows_ul = psAlloc(nx*ny*sizeof(unsigned long));
     88        image->rows.rows_ul = psAlloc(nCols*nRows*sizeof(unsigned long));
    8789        break;
    8890    case PS_TYPE_FLOAT:
    89         image->rows.rows_f = psAlloc(nx*ny*sizeof(float));
     91        image->rows.rows_f = psAlloc(nCols*nRows*sizeof(float));
    9092        break;
    9193    case PS_TYPE_DOUBLE:
    92         image->rows.rows_d = psAlloc(nx*ny*sizeof(double));
     94        image->rows.rows_d = psAlloc(nCols*nRows*sizeof(double));
    9395        break;
    9496    case PS_TYPE_COMPLEX:
    95         image->rows.rows_cf = psAlloc(nx*ny*sizeof(complex float));
    96         break;
    97     case PS_TYPE_OTHER:
    98         psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
     97        image->rows.rows_cf = psAlloc(nCols*nRows*sizeof(complex float));
    9998        break;
    10099    default:
    101         psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
     100        psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, type.type);
    102101    }
    103102
     103    return image;
     104}
    104105
     106void psImageFree(psImage *image)
     107{
     108    int i = 0;
     109    int nChildren = 0;
     110    psElemType imageType = 0;
     111    psImage *children = NULL;
     112
     113    if(image != NULL) {
     114        imageType = image->type.type;
     115        nChildren = image->nChildren;
     116        children = image->children;
     117
     118        switch(imageType) {
     119        case PS_TYPE_SHORT:
     120            psFree(image->rows.rows_s);
     121            break;
     122        case PS_TYPE_INT:
     123            psFree(image->rows.rows_i);
     124            break;
     125        case PS_TYPE_LONG:
     126            psFree(image->rows.rows_l);
     127            break;
     128        case PS_TYPE_USHORT:
     129            psFree(image->rows.rows_us);
     130            break;
     131        case PS_TYPE_UINT:
     132            psFree(image->rows.rows_ui);
     133            break;
     134        case PS_TYPE_ULONG:
     135            psFree(image->rows.rows_ul);
     136            break;
     137        case PS_TYPE_FLOAT:
     138            psFree(image->rows.rows_f);
     139            break;
     140        case PS_TYPE_DOUBLE:
     141            psFree(image->rows.rows_d);
     142            break;
     143        case PS_TYPE_COMPLEX:
     144            psFree(image->rows.rows_cf);
     145            break;
     146        case PS_TYPE_OTHER:
     147            psError(__func__, " : Line %d - Can't delete images of type PS_TYPE_OTHER\n", __LINE__);
     148            break;
     149        default:
     150            psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, imageType);
     151        }
     152
     153        for(i=0; i<nChildren; i++) {
     154            psImageFree(children);
     155        }
     156    }
    105157}
  • trunk/psLib/src/mathtypes/psImage.h

    r599 r633  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-07 02:56:52 $
     9 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-10 20:20:42 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636{
    3737    psType type;                    ///< Image data type and dimension.
    38     int nx, ny;                     ///< Size of image.
    39     int x0, y0;                     ///< Data region relative to parent.
     38    int nCols;                      ///< Number of rows in image
     39    int nRows;                      ///< Number of columns in image.
     40    int col0;                       ///< Row position relative to parent.
     41    int row0;                       ///< Column position relative to parent.
    4042    union {
    41         float **rows                ///< Pointers to floating point data (default).
    4243        short **rows_s;             ///< Pointers to short integer data.
    4344        int **rows_i;               ///< Pointers to integer data.
     
    4647        unsigned int **rows_ui;     ///< Pointers to unsigned integer data.
    4748        unsigned long **rows_ul;    ///< Pointers to unsigned long integer data.
    48         float **rows_f              ///< Pointers to floating point data.
    49         double **rows_d             ///< Pointers to double precision data.
    50         complex float **rows_cf     ///< Pointers to complex floating point data.
     49        float **rows_f;             ///< Pointers to floating point data.
     50        double **rows_d;            ///< Pointers to double precision data.
     51        complex float **rows_cf;    ///< Pointers to complex floating point data.
    5152    } rows;                         ///< Union for data types.
    5253    struct psImage *parent;         ///< Parent, if a subimage.
     
    6970 */
    7071psImage *psImageAlloc(
    71     int nx,     ///< Image width.
    72     int ny,     ///< Image height.
    73     psType type ///< Image data type.
     72    int nCols,  ///< Number of rows in image.
     73    int nRows,  ///< Number of columns in image.
     74    psType type ///< Type of data for image.
    7475);
    7576
     
    8485    psImage *out,           ///< Subimage to return, or NULL.
    8586    const psImage *image,   ///< Parent image.
    86     int nx,                 ///< Subimage width (<= image.nx - x0).
    87     int ny,                 ///< Subimage width (<= image.ny - y0).
    88     int x0,                 ///< Subimage x-offset (0 <= x0 < nx).
    89     int y0                  ///< Subimage y-offset (0 <= y0 < ny).
     87    int nCols,              ///< Subimage width (<= image.nCols - col0).
     88    int nRows,              ///< Subimage height (<= image.nRows - row0).
     89    int col0,               ///< Subimage col-offset (0 <= col0 < nCol).
     90    int row0                ///< Subimage row-offset (0 <= row0 < nCol).
    9091);
    9192
     
    9899 */
    99100void psImageFree(
    100     psImage *restrict image ///< free this image
     101    psImage *restrict image ///< Free psImage
    101102);
    102103
    103 
    104 
    105 // DOXYGEN COMMENTING FORMAT NOT YET FULLY IMPLEMENTED BEYOND THIS POINT
    106 
    107 
    108 
    109 /** Destroy the pixels of the specified image */
    110 psImage *
    111 psImageFreePixels(psImage *restrict image ///< Image whose pixels are to be freed
    112                  );
    113 
    114 /// Destroy the children of the specified image.  Returns number of children freed.
    115 int
    116 psImageFreeChildren(const psImage *image ///< free children of this image
    117                    );
    118 
    119 /// Create a copy of the specified image.
    120 psImage *
    121 psImageCopy(psImage *output,   ///< target structure for output image data
    122             const psImage *input ///< copy this image
    123            );
    124 
    125 /*** various image pixel extractions ***/
    126 
    127 /// Extract pixels from rectlinear region to a vector.
    128 psFloatArray *
    129 psImageSlice(psFloatArray *out,  ///< Vector to output, or NULL
    130              const psImage *input, ///< extract slice from this image
    131              int x,    ///< starting x coord of region to slice
    132              int y,    ///< starting y coord of region to slice
    133              int nx,    ///< width of region in x
    134              int ny,    ///< width of region in y
    135              int direction,  ///< direction of vector along slice
    136              const psStats *stats ///< defines statistics used to find output values
    137             );
    138 
    139 /// Extract pixels along a line to a vector.
    140 psFloatArray *
    141 psImageCut(psFloatArray *out,  ///< Vector to output, or NULL
    142            const psImage *input, ///< extract cut from this image
    143            float xs,    ///< starting x coord of cut
    144            float ys,    ///< starting y coord of cut
    145            float xe,    ///< ending x coord of cut
    146            float ye,    ///< ending y coord of cut
    147            float dw,    ///< width of cut
    148            const psStats *stats  ///< defines statistics used to find output values
    149           );
    150 
    151 /// Extract radial annulii data to a vector.
    152 psFloatArray *
    153 psImageRadialCut(psFloatArray *out, ///< Vector to output, or NULL
    154                  const psImage *input, ///< extract profile from this image
    155                  float x,   ///< center x coord of annulii
    156                  float y,   ///< center y coord of annulii
    157                  float radius,  ///< outer radius of annulii
    158                  float dr,  ///< radial step size of annulii
    159                  const psStats *stats ///< defines statistics used to find output values
    160                 );
    161 
    162 /* Contour is a high-level function */
    163 #if 0
    164 /// Extract a 2-d contour from an image at the given threshold.
    165 psFloatArray *
    166 psImageContour(psFloatArray *out, ///< Vector to output, or NULL
    167                const psImage *input,  ///< create contour for this image
    168                float threshold, ///< contour image at this threshold
    169                int binning  ///< bin image by this value for contour calculation
    170               );
    171104#endif
    172 
    173 /*** various image geometry manipulation ***/
    174 /// Rebin image to new scale.
    175 psImage *
    176 psImageRebin(psImage *out,  ///< Image to output, or NULL
    177              const psImage *input, ///< rebin this image
    178              float scale,   ///< rebinning scale: doutput = scale*dinput
    179              const psStats *stats ///< defines statistics used to find output values
    180             );
    181 
    182 /// Rotate image by given angle.
    183 psImage *
    184 psImageRotate(psImage *out,  ///< Image to output, or NULL
    185               const psImage *input, ///< rotate this image
    186               float angle  ///< rotate by this amount anti-clockwise (degrees)
    187              );
    188 
    189 /// Shift image by an arbitrary number of pixels in either direction.
    190 /// Drop edge pixels, and set newly exposed pixels to 'exposed'.
    191 psImage *
    192 psImageShift(psImage *out,  ///< Image to output, or NULL
    193              const psImage *input, ///< shift this image
    194              float dx,   ///< shift by this amount in x
    195              float dy,   ///< shift by this amount in y
    196              float exposed  ///< set exposed pixels to this value
    197             );
    198 
    199 /// Roll image by an integer number of pixels in either direction.
    200 /// Edge pixels wrap to the other side (no values are lost).
    201 psImage *
    202 psImageRoll(psImage *out,  ///< Image to output, or NULL
    203             const psImage *input, ///< roll this image
    204             int dx,    ///< roll this amount in x
    205             int dy   ///< roll this amount in y
    206            );
    207 
    208 /// Determine statistics for image (or subimage).
    209 psStats *
    210 psImageGetStats(const psImage *input,  ///< image (or subimage) to calculate stats
    211                 psStats *stats  ///< defines statistics to be calculated & target
    212                );
    213 
    214 /// Construct a histogram from an image (or subimage).
    215 psHistogram *
    216 psImageHistogram(psHistogram *hist, ///< input histogram description & target
    217                  const psImage *input ///< determine histogram of this image
    218                 );
    219 
    220 /// Fit a 2-D polynomial surface to an image.
    221 psPolynomial2D *
    222 psImageFitPolynomial(const psImage *input, ///< image to fit
    223                      psPolynomial2D *coeffs ///< coefficient structure carries in desired terms & target
    224                     );
    225 
    226 /// Evaluate a 2-D polynomial surface to image pixels.
    227 int
    228 psImageEvalPolynomial(const psImage *input, ///< image to fit
    229                       const psPolynomial2D *coeffs ///< coefficient structure carries in desired terms
    230                      );
    231 
    232 /*** image input/output routines ***/
    233 /// Read an image or subimage from a named file.
    234 psImage *
    235 psImageReadSection(psImage *output,  ///< place data in this structure for output
    236                    int x,   ///< starting x coord of region
    237                    int y,   ///< starting y coord of region
    238                    int nx,   ///< x size of region (-1 for full range)
    239                    int ny,   ///< y size of region (-1 for full range)
    240                    int z,   ///< plane of interest
    241                    const char *extname, ///< MEF extension name ("PHU" for primary header)
    242                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    243                    const char *filename ///< file to read data from
    244                   );
    245 
    246 /// Read an image or subimage from file descriptor.
    247 psImage *
    248 psImageFReadSection(psImage *output, ///< place data in this structure for output
    249                     int x,  ///< starting x coord of region
    250                     int y,  ///< starting y coord of region
    251                     int nx,  ///< x size of region (-1 for full range)
    252                     int ny,  ///< y size of region (-1 for full range)
    253                     int z,  ///< plane of interest
    254                     const char *extname, ///< MEF extension name ("PHU" for primary header)
    255                     int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    256                     FILE *f  ///< file descriptor to read data from
    257                    );
    258 
    259 /// Write an image section to named file (which may exist).
    260 psImage *
    261 psImageWriteSection(psImage *input,    ///< image to write out
    262                     int x,   ///< starting x coord of region
    263                     int y,   ///< starting y coord of region
    264                     int z,   ///< plane of interest
    265                     const char *extname, ///< MEF extension name ("PHU" for primary header)
    266                     int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    267                     const char *filename ///< file to write data to
    268                    );
    269 
    270 /// Write an image section to named file (which may exist).
    271 psImage *
    272 psImageFWriteSection(psImage *input, ///< image to write out
    273                      int x,   ///< starting x coord of region
    274                      int y,   ///< starting y coord of region
    275                      int z,   ///< plane of interest
    276                      const char *extname, ///< MEF extension name
    277                      int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    278                      FILE *f  ///< file descriptor to write data to
    279                     );
    280 
    281 /// Read only header from image file.
    282 psMetadata *
    283 psImageReadHeader(psMetadata *output, ///< read data to this structure
    284                   const char *extname,  ///< MEF extension name ("PHU" for primary header)
    285                   int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    286                   const char *filename ///< file to read from
    287                  );
    288 
    289 /// Read only header from image file descriptor.
    290 psMetadata *
    291 psImageFReadHeader(psMetadata *output, ///< read data to this structure
    292                    const char *extname, ///< MEF extension name ("PHU" for primary header)
    293                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
    294                    FILE *f  ///< file descriptor to read from
    295                   );
    296 
    297 /*** basic pixel manipulations ***/
    298 /// Clip image values outside of range to given values.  Return number of clipped pixels.
    299 int
    300 psImageClip(psImage *input,   ///< clip this image
    301             float min,   ///< clip pixels with values < min
    302             float vmin,   ///< set min-clipped pixels to vmin
    303             float max,   ///< clip pixels with values > max
    304             float vmax   ///< set max-clipped pixels to vmax
    305            );
    306 
    307 /// Clip NaN image pixels to given value.  Return number of clipped pixels.
    308 int
    309 psImageClipNaN(psImage *input,  ///< clip this image & target
    310                float value  ///< set nan pixels to this value
    311               );
    312 
    313 /// Overlay subregion of image with another image.  Return number of pixels replaced.
    314 int
    315 psImageOverlaySection(psImage *image, ///< input image & target
    316                       const psImage *overlay, ///< image to overlay
    317                       int x0,  ///< x offset of overlay subimage
    318                       int y0,  ///< y offset of overlay subimage
    319                       const char *op ///< overlay operation
    320                      );
    321 
    322 /* \} */ // End of AstroGroup Functions
    323 
    324 # endif
    325 /* image overlay operations
    326     PS_OVERLAY_EQUALS   = '=',
    327     PS_OVERLAY_ADD      = '+',
    328     PS_OVERLAY_SUBTRACT = '-',
    329     PS_OVERLAY_MULTIPLY = '*',
    330     PS_OVERLAY_DIVIDE   = '/',
    331 */
Note: See TracChangeset for help on using the changeset viewer.