IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1205


Ignore:
Timestamp:
Jul 9, 2004, 11:48:07 AM (22 years ago)
Author:
desonia
Message:

Moved psImage manipulation functions from collections/psImage.[ch] to dataManip/psImageManip.[ch].

Location:
trunk/psLib/src
Files:
2 added
6 edited

Legend:

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

    r1111 r1205  
    33##  Makefile:   collections
    44##
    5 ##  $Revision: 1.22 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-06-28 20:36:37 $
     5##  $Revision: 1.23 $  $Name: not supported by cvs2svn $
     6##  $Date: 2004-07-09 21:48:07 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4141
    4242all: $(TARGET_STATIC)
    43 
    44 # force the creation of a psImage.i for psImage.o (to expand macros).
    45 psImage.o: psImage.i
    4643
    4744# Rule to make static library
  • trunk/psLib/src/dataManip/Makefile

    r1185 r1205  
    1414           psFFT.o \
    1515           psImageIO.o \
    16            psMinimize.o
     16           psMinimize.o \
     17           psImageManip.o
    1718
    1819all: $(TARGET_STATIC)
  • trunk/psLib/src/image/psImage.c

    r1193 r1205  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-07-08 01:05:00 $
     11 *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-07-09 21:48:07 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    400400}
    401401
    402 int psImageClip(psImage* input,float min,float vmin,float max,float vmax)
    403 {
    404     int numClipped = 0;
    405     unsigned int numRows;
    406     unsigned int numCols;
    407 
    408     if (input == NULL) {
    409         return 0;
    410     }
    411 
    412     if (max < min) {
    413         psError(__func__,"psImageClip can not be invoked with max < min.");
    414         return 0;
    415     }
    416 
    417     numRows = input->numRows;
    418     numCols = input->numCols;
    419 
    420     switch (input->type.type) {
    421 
    422         #define psImageClipCase(type)\
    423     case PS_TYPE_##type: { \
    424             ps##type minimum = (ps##type) min; \
    425             ps##type maximum = (ps##type) max; \
    426             for (unsigned int row = 0;row<numRows;row++) { \
    427                 ps##type* inputRow = input->data.type[row]; \
    428                 for (unsigned int col = 0; col < numCols; col++) { \
    429                     if (inputRow[col] < minimum) { \
    430                         inputRow[col] = (ps##type)vmin; \
    431                         numClipped++; \
    432                     } else if (inputRow[col] > maximum) { \
    433                         inputRow[col] = (ps##type)vmax; \
    434                         numClipped++; \
    435                     } \
    436                 } \
    437             } \
    438         } \
    439         break;
    440         #define psImageClipCaseComplex(type)\
    441     case PS_TYPE_##type: { \
    442             for (unsigned int row = 0;row<numRows;row++) { \
    443                 ps##type* inputRow = input->data.type[row]; \
    444                 for (unsigned int col = 0; col < numCols; col++) { \
    445                     if (cabsf(inputRow[col]) < min) { \
    446                         inputRow[col] = (ps##type)vmin; \
    447                         numClipped++; \
    448                     } else if (cabsf(inputRow[col]) > max) { \
    449                         inputRow[col] = (ps##type)vmax; \
    450                         numClipped++; \
    451                     } \
    452                 } \
    453             } \
    454         } \
    455         break;
    456 
    457         psImageClipCase(S8)
    458         psImageClipCase(S16)
    459         psImageClipCase(S32)
    460         psImageClipCase(S64)
    461         psImageClipCase(U8)
    462         psImageClipCase(U16)
    463         psImageClipCase(U32)
    464         psImageClipCase(U64)
    465         psImageClipCase(F32)
    466         psImageClipCase(F64)
    467         psImageClipCaseComplex(C32)
    468         psImageClipCaseComplex(C64)
    469 
    470     default:
    471         psError(__func__,"psImageClip does not support the given datatype (%d)",
    472                 input->type.type);
    473     }
    474 
    475     return numClipped;
    476 }
    477 
    478 int psImageClipNaN(psImage* input,float value)
    479 {
    480     int numClipped = 0;
    481     unsigned int numRows;
    482     unsigned int numCols;
    483 
    484     if (input == NULL) {
    485         return 0;
    486     }
    487     numRows = input->numRows;
    488     numCols = input->numCols;
    489 
    490     switch (input->type.type) {
    491 
    492         #define psImageClipNaNCase(type) \
    493     case PS_TYPE_##type: \
    494         for (unsigned int row = 0;row<numRows;row++) { \
    495             ps##type* inputRow = input->data.type[row]; \
    496             for (unsigned int col = 0; col < numCols; col++) { \
    497                 if (! isfinite(inputRow[col])) { \
    498                     inputRow[col] = (ps##type)value; \
    499                     numClipped++; \
    500                 } \
    501             } \
    502         } \
    503         break;
    504 
    505         psImageClipNaNCase(F32)
    506         psImageClipNaNCase(F64)
    507         psImageClipNaNCase(C32)
    508         psImageClipNaNCase(C64)
    509 
    510     default:
    511         psError(__func__,"psImageClip does not support the given datatype (%d)",
    512                 input->type.type);
    513     }
    514 
    515     return numClipped;
    516 }
    517 
    518 int psImageOverlaySection(psImage* image, const psImage* overlay, int col0,
    519                           int row0, const char* op)
    520 {
    521     unsigned int imageNumRows;
    522     unsigned int imageNumCols;
    523     unsigned int overlayNumRows;
    524     unsigned int overlayNumCols;
    525     unsigned int imageRowLimit;
    526     unsigned int imageColLimit;
    527     psElemType  type;
    528 
    529     if (image == NULL || overlay == NULL) {
    530         psError(__func__,"one of the input images was NULL.");
    531         return 1;
    532     }
    533 
    534     if (op == NULL) {
    535         psError(__func__,"Operation can not be NULL.");
    536         return 1;
    537     }
    538 
    539     type = image->type.type;
    540 
    541     if (type != overlay->type.type) {
    542         psError(__func__,"Image and overlay datatypes must match. (%d vs %d)",
    543                 type,overlay->type.type);
    544         return 2;
    545     }
    546 
    547     imageNumRows = image->numRows;
    548     imageNumCols = image->numCols;
    549     overlayNumRows = overlay->numRows;
    550     overlayNumCols = overlay->numCols;
    551 
    552     /* check row0/col0 to see if it is within the image size */
    553     if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
    554         psError(__func__, "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
    555                 col0, row0, imageNumCols, imageNumRows);
    556         return 3;
    557     }
    558 
    559     /* check if overlay is totally withing input image */
    560     imageRowLimit = row0+overlayNumRows;
    561     imageColLimit = col0+overlayNumCols;
    562     if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
    563         psError(__func__, "Overlay image (%d,%d -> %d,%d) is partially outside"
    564                 " of the input image (%d x %d).",
    565                 col0, row0, col0+overlayNumCols-1, row0+overlayNumRows-1,
    566                 imageNumCols,imageNumRows);
    567         return 4;
    568     }
    569 
    570     switch (type) {
    571 
    572         #define psImageOverlayCase(DATATYPE) \
    573     case PS_TYPE_##DATATYPE: \
    574         for (unsigned int row=row0;row<imageRowLimit;row++) { \
    575             ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
    576             ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
    577             for (unsigned int col=col0;col<imageColLimit;col++) { \
    578                 switch (*op) { \
    579                 case '+': \
    580                     imageRow[col] += overlayRow[col-col0]; \
    581                     break; \
    582                 case '-': \
    583                     imageRow[col] -= overlayRow[col-col0]; \
    584                     break; \
    585                 case '*': \
    586                     imageRow[col] *= overlayRow[col-col0]; \
    587                     break; \
    588                 case '/': \
    589                     imageRow[col] /= overlayRow[col-col0]; \
    590                     break; \
    591                 case '=': \
    592                     imageRow[col] = overlayRow[col-col0]; \
    593                     break; \
    594                 default: \
    595                     psError(__func__,"Unknown operation %s",op); \
    596                     return 5; \
    597                 } \
    598             } \
    599         } \
    600         break;
    601 
    602         psImageOverlayCase(U8);
    603         psImageOverlayCase(U16);
    604         psImageOverlayCase(U32);
    605         psImageOverlayCase(U64);
    606         psImageOverlayCase(S8);
    607         psImageOverlayCase(S16);
    608         psImageOverlayCase(S32);
    609         psImageOverlayCase(S64);
    610         psImageOverlayCase(F32);
    611         psImageOverlayCase(F64);
    612         psImageOverlayCase(C32);
    613         psImageOverlayCase(C64);
    614 
    615     default:
    616         psError(__func__,"Can not operate on type %d.",type);
    617     }
    618 
    619     return 0;
    620 }
  • trunk/psLib/src/image/psImage.h

    r1073 r1205  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-23 23:00:15 $
     13 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-07-09 21:48:07 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    137137);
    138138
    139 /** Clip image values outside of tange to given values
    140  *
    141  *  All pixels with values less than min are set to the value vmin.  all pixels
    142  *  with values greater than max are set to the value vmax. This function is
    143  *  defined for psU8, psU16, psS8, psS16, psF32, psF64, psC32, and psC64.
    144  *
    145  *  @return int     The number of clipped pixels
    146  */
    147 int psImageClip(
    148     psImage* input,                 ///< the image to clip
    149     psF32 min,                      ///< the minimum image value allowed
    150     psF32 vmin,                     ///< the value pixels < min are set to
    151     psF32 max,                      ///< the maximum image value allowed
    152     psF32 vmax                      ///< the value pixels > max are set to
    153 );
    154 
    155 /** Clip NaN image pixels to given value.
    156  *
    157  *  Pixels with NaN, +Inf, or -Inf values are set to the specified value. This
    158  *  function is defined for psF32, psF64, psC32, and psC64.
    159  *
    160  *  @return int     The number of clipped pixels
    161  */
    162 int psImageClipNaN(
    163     psImage* input,                 ///< the image to clip
    164     psF32 value                     ///< the value to set all NaN/Inf values to
    165 );
    166 
    167 /** Overlay subregion of image with another image
    168  *
    169  *  Replace the pixels in the image which correspond to the pixels in OVERLAY
    170  *  with values derived from the IMAGE and OVERLAY based on the given operator
    171  *  OP.  Valid operators are "=" (set image value to OVERLAY value), "+" (add
    172  *  OVERLAY value to image value), "-" (subtract OVERLAY from image), "*"
    173  *  (multiply OVERLAY times image), "/" (divide image by OVERLAY).  This
    174  *  function is defined for psU8, psS8, psS16, psF32, psF64, psC32, and psC64.
    175  *
    176  *  @return int         0 if success, non-zero if failed.
    177  */
    178 int psImageOverlaySection(
    179     psImage* image,                 ///< target image
    180     const psImage* overlay,         ///< the overlay image
    181     int col0,                       ///< the column to start overlay
    182     int row0,                       ///< the row to start overlay
    183     const char* op                  ///< the operation to perform for overlay
    184 );
    185 
    186139/// @}
    187140
  • trunk/psLib/src/mathtypes/psImage.c

    r1193 r1205  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-07-08 01:05:00 $
     11 *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-07-09 21:48:07 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    400400}
    401401
    402 int psImageClip(psImage* input,float min,float vmin,float max,float vmax)
    403 {
    404     int numClipped = 0;
    405     unsigned int numRows;
    406     unsigned int numCols;
    407 
    408     if (input == NULL) {
    409         return 0;
    410     }
    411 
    412     if (max < min) {
    413         psError(__func__,"psImageClip can not be invoked with max < min.");
    414         return 0;
    415     }
    416 
    417     numRows = input->numRows;
    418     numCols = input->numCols;
    419 
    420     switch (input->type.type) {
    421 
    422         #define psImageClipCase(type)\
    423     case PS_TYPE_##type: { \
    424             ps##type minimum = (ps##type) min; \
    425             ps##type maximum = (ps##type) max; \
    426             for (unsigned int row = 0;row<numRows;row++) { \
    427                 ps##type* inputRow = input->data.type[row]; \
    428                 for (unsigned int col = 0; col < numCols; col++) { \
    429                     if (inputRow[col] < minimum) { \
    430                         inputRow[col] = (ps##type)vmin; \
    431                         numClipped++; \
    432                     } else if (inputRow[col] > maximum) { \
    433                         inputRow[col] = (ps##type)vmax; \
    434                         numClipped++; \
    435                     } \
    436                 } \
    437             } \
    438         } \
    439         break;
    440         #define psImageClipCaseComplex(type)\
    441     case PS_TYPE_##type: { \
    442             for (unsigned int row = 0;row<numRows;row++) { \
    443                 ps##type* inputRow = input->data.type[row]; \
    444                 for (unsigned int col = 0; col < numCols; col++) { \
    445                     if (cabsf(inputRow[col]) < min) { \
    446                         inputRow[col] = (ps##type)vmin; \
    447                         numClipped++; \
    448                     } else if (cabsf(inputRow[col]) > max) { \
    449                         inputRow[col] = (ps##type)vmax; \
    450                         numClipped++; \
    451                     } \
    452                 } \
    453             } \
    454         } \
    455         break;
    456 
    457         psImageClipCase(S8)
    458         psImageClipCase(S16)
    459         psImageClipCase(S32)
    460         psImageClipCase(S64)
    461         psImageClipCase(U8)
    462         psImageClipCase(U16)
    463         psImageClipCase(U32)
    464         psImageClipCase(U64)
    465         psImageClipCase(F32)
    466         psImageClipCase(F64)
    467         psImageClipCaseComplex(C32)
    468         psImageClipCaseComplex(C64)
    469 
    470     default:
    471         psError(__func__,"psImageClip does not support the given datatype (%d)",
    472                 input->type.type);
    473     }
    474 
    475     return numClipped;
    476 }
    477 
    478 int psImageClipNaN(psImage* input,float value)
    479 {
    480     int numClipped = 0;
    481     unsigned int numRows;
    482     unsigned int numCols;
    483 
    484     if (input == NULL) {
    485         return 0;
    486     }
    487     numRows = input->numRows;
    488     numCols = input->numCols;
    489 
    490     switch (input->type.type) {
    491 
    492         #define psImageClipNaNCase(type) \
    493     case PS_TYPE_##type: \
    494         for (unsigned int row = 0;row<numRows;row++) { \
    495             ps##type* inputRow = input->data.type[row]; \
    496             for (unsigned int col = 0; col < numCols; col++) { \
    497                 if (! isfinite(inputRow[col])) { \
    498                     inputRow[col] = (ps##type)value; \
    499                     numClipped++; \
    500                 } \
    501             } \
    502         } \
    503         break;
    504 
    505         psImageClipNaNCase(F32)
    506         psImageClipNaNCase(F64)
    507         psImageClipNaNCase(C32)
    508         psImageClipNaNCase(C64)
    509 
    510     default:
    511         psError(__func__,"psImageClip does not support the given datatype (%d)",
    512                 input->type.type);
    513     }
    514 
    515     return numClipped;
    516 }
    517 
    518 int psImageOverlaySection(psImage* image, const psImage* overlay, int col0,
    519                           int row0, const char* op)
    520 {
    521     unsigned int imageNumRows;
    522     unsigned int imageNumCols;
    523     unsigned int overlayNumRows;
    524     unsigned int overlayNumCols;
    525     unsigned int imageRowLimit;
    526     unsigned int imageColLimit;
    527     psElemType  type;
    528 
    529     if (image == NULL || overlay == NULL) {
    530         psError(__func__,"one of the input images was NULL.");
    531         return 1;
    532     }
    533 
    534     if (op == NULL) {
    535         psError(__func__,"Operation can not be NULL.");
    536         return 1;
    537     }
    538 
    539     type = image->type.type;
    540 
    541     if (type != overlay->type.type) {
    542         psError(__func__,"Image and overlay datatypes must match. (%d vs %d)",
    543                 type,overlay->type.type);
    544         return 2;
    545     }
    546 
    547     imageNumRows = image->numRows;
    548     imageNumCols = image->numCols;
    549     overlayNumRows = overlay->numRows;
    550     overlayNumCols = overlay->numCols;
    551 
    552     /* check row0/col0 to see if it is within the image size */
    553     if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
    554         psError(__func__, "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
    555                 col0, row0, imageNumCols, imageNumRows);
    556         return 3;
    557     }
    558 
    559     /* check if overlay is totally withing input image */
    560     imageRowLimit = row0+overlayNumRows;
    561     imageColLimit = col0+overlayNumCols;
    562     if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
    563         psError(__func__, "Overlay image (%d,%d -> %d,%d) is partially outside"
    564                 " of the input image (%d x %d).",
    565                 col0, row0, col0+overlayNumCols-1, row0+overlayNumRows-1,
    566                 imageNumCols,imageNumRows);
    567         return 4;
    568     }
    569 
    570     switch (type) {
    571 
    572         #define psImageOverlayCase(DATATYPE) \
    573     case PS_TYPE_##DATATYPE: \
    574         for (unsigned int row=row0;row<imageRowLimit;row++) { \
    575             ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
    576             ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
    577             for (unsigned int col=col0;col<imageColLimit;col++) { \
    578                 switch (*op) { \
    579                 case '+': \
    580                     imageRow[col] += overlayRow[col-col0]; \
    581                     break; \
    582                 case '-': \
    583                     imageRow[col] -= overlayRow[col-col0]; \
    584                     break; \
    585                 case '*': \
    586                     imageRow[col] *= overlayRow[col-col0]; \
    587                     break; \
    588                 case '/': \
    589                     imageRow[col] /= overlayRow[col-col0]; \
    590                     break; \
    591                 case '=': \
    592                     imageRow[col] = overlayRow[col-col0]; \
    593                     break; \
    594                 default: \
    595                     psError(__func__,"Unknown operation %s",op); \
    596                     return 5; \
    597                 } \
    598             } \
    599         } \
    600         break;
    601 
    602         psImageOverlayCase(U8);
    603         psImageOverlayCase(U16);
    604         psImageOverlayCase(U32);
    605         psImageOverlayCase(U64);
    606         psImageOverlayCase(S8);
    607         psImageOverlayCase(S16);
    608         psImageOverlayCase(S32);
    609         psImageOverlayCase(S64);
    610         psImageOverlayCase(F32);
    611         psImageOverlayCase(F64);
    612         psImageOverlayCase(C32);
    613         psImageOverlayCase(C64);
    614 
    615     default:
    616         psError(__func__,"Can not operate on type %d.",type);
    617     }
    618 
    619     return 0;
    620 }
  • trunk/psLib/src/mathtypes/psImage.h

    r1073 r1205  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-23 23:00:15 $
     13 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-07-09 21:48:07 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    137137);
    138138
    139 /** Clip image values outside of tange to given values
    140  *
    141  *  All pixels with values less than min are set to the value vmin.  all pixels
    142  *  with values greater than max are set to the value vmax. This function is
    143  *  defined for psU8, psU16, psS8, psS16, psF32, psF64, psC32, and psC64.
    144  *
    145  *  @return int     The number of clipped pixels
    146  */
    147 int psImageClip(
    148     psImage* input,                 ///< the image to clip
    149     psF32 min,                      ///< the minimum image value allowed
    150     psF32 vmin,                     ///< the value pixels < min are set to
    151     psF32 max,                      ///< the maximum image value allowed
    152     psF32 vmax                      ///< the value pixels > max are set to
    153 );
    154 
    155 /** Clip NaN image pixels to given value.
    156  *
    157  *  Pixels with NaN, +Inf, or -Inf values are set to the specified value. This
    158  *  function is defined for psF32, psF64, psC32, and psC64.
    159  *
    160  *  @return int     The number of clipped pixels
    161  */
    162 int psImageClipNaN(
    163     psImage* input,                 ///< the image to clip
    164     psF32 value                     ///< the value to set all NaN/Inf values to
    165 );
    166 
    167 /** Overlay subregion of image with another image
    168  *
    169  *  Replace the pixels in the image which correspond to the pixels in OVERLAY
    170  *  with values derived from the IMAGE and OVERLAY based on the given operator
    171  *  OP.  Valid operators are "=" (set image value to OVERLAY value), "+" (add
    172  *  OVERLAY value to image value), "-" (subtract OVERLAY from image), "*"
    173  *  (multiply OVERLAY times image), "/" (divide image by OVERLAY).  This
    174  *  function is defined for psU8, psS8, psS16, psF32, psF64, psC32, and psC64.
    175  *
    176  *  @return int         0 if success, non-zero if failed.
    177  */
    178 int psImageOverlaySection(
    179     psImage* image,                 ///< target image
    180     const psImage* overlay,         ///< the overlay image
    181     int col0,                       ///< the column to start overlay
    182     int row0,                       ///< the row to start overlay
    183     const char* op                  ///< the operation to perform for overlay
    184 );
    185 
    186139/// @}
    187140
Note: See TracChangeset for help on using the changeset viewer.