IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1319


Ignore:
Timestamp:
Jul 28, 2004, 3:20:10 PM (22 years ago)
Author:
desonia
Message:

tested psImageClipComplexRegion.

Location:
trunk/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/psLib.kdevses

    r1308 r1319  
    22<!DOCTYPE KDevPrjSession>
    33<KDevPrjSession>
    4  <DocsAndViews NumberOfDocuments="9" >
    5   <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageExtraction.c" >
    6    <View0 line="362" Type="???" >
    7     <AdditionalSettings Top="2" Width="1270" Attach="1" Height="779" Left="2" MinMaxMode="0" />
     4 <DocsAndViews NumberOfDocuments="3" >
     5  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageManip.c" >
     6   <View0 line="0" Type="???" >
     7    <AdditionalSettings Top="2" Width="1227" Attach="1" Height="794" Left="2" MinMaxMode="0" />
    88   </View0>
    99  </Doc0>
    10   <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageExtraction.h" >
    11    <View0 line="75" Type="???" >
    12     <AdditionalSettings Top="2" Width="1526" Attach="1" Height="954" Left="2" MinMaxMode="0" />
     10  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/test/image/tst_psImageManip.c" >
     11   <View0 line="424" Type="???" >
     12    <AdditionalSettings Top="2" Width="1227" Attach="1" Height="769" Left="2" MinMaxMode="0" />
    1313   </View0>
    1414  </Doc1>
    15   <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psVector.h" >
    16    <View0 line="0" Type="???" >
    17     <AdditionalSettings Top="2" Width="1243" Attach="1" Height="827" Left="2" MinMaxMode="0" />
     15  <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/astronomy/psCCD.h" >
     16   <View0 line="93" Type="???" >
     17    <AdditionalSettings Top="2" Width="1227" Attach="1" Height="769" Left="2" MinMaxMode="0" />
    1818   </View0>
    1919  </Doc2>
    20   <Doc3 NumberOfViews="1" URL="file:/home/desonia/psLib/src/dataManip/psStats.h" >
    21    <View0 line="0" Type="???" >
    22     <AdditionalSettings Top="2" Width="1243" Attach="1" Height="827" Left="2" MinMaxMode="0" />
    23    </View0>
    24   </Doc3>
    25   <Doc4 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageManip.c" >
    26    <View0 line="463" Type="???" >
    27     <AdditionalSettings Top="2" Width="1196" Attach="1" Height="939" Left="2" MinMaxMode="0" />
    28    </View0>
    29   </Doc4>
    30   <Doc5 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psType.h" >
    31    <View0 line="120" Type="???" >
    32     <AdditionalSettings Top="2" Width="1270" Attach="1" Height="779" Left="2" MinMaxMode="0" />
    33    </View0>
    34   </Doc5>
    35   <Doc6 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageIO.h" >
    36    <View0 line="0" Type="???" >
    37     <AdditionalSettings Top="2" Width="1270" Attach="1" Height="779" Left="2" MinMaxMode="0" />
    38    </View0>
    39   </Doc6>
    40   <Doc7 NumberOfViews="1" URL="file:/home/desonia/psLib/src/image/psImageManip.h" >
    41    <View0 line="0" Type="???" >
    42     <AdditionalSettings Top="2" Width="1196" Attach="1" Height="939" Left="2" MinMaxMode="0" />
    43    </View0>
    44   </Doc7>
    45   <Doc8 NumberOfViews="1" URL="file:/home/desonia/psLib/test/dataManip/tst_psImageStats03.c" >
    46    <View0 line="35" Type="???" >
    47     <AdditionalSettings Top="2" Width="1526" Attach="1" Height="942" Left="2" MinMaxMode="0" />
    48    </View0>
    49   </Doc8>
    5020 </DocsAndViews>
    5121 <pluginList>
  • trunk/psLib/src/image/psImageManip.c

    r1292 r1319  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-24 02:00:21 $
     12 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-29 01:20:10 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    276276
    277277    if (input == NULL) {
     278        psError(__func__,"Can not perform clip on NULL image");
    278279        return 0;
    279280    }
     
    301302                psError(__func__, "Specified vmin (%g%+gi) is outside of image's " \
    302303                        typename " pixel range", \
    303                         realfcn(vmin),imagfcn(vmin)); \
     304                        creal(vmin),cimag(vmin)); \
     305                break; \
    304306            } \
    305307            if (realfcn(vmax) > PS_MAX_##type || imagfcn(vmax) > PS_MAX_##type || \
     
    307309                psError(__func__, "Specified vmax (%g%+gi) is outside of image's " \
    308310                        typename " pixel range", \
    309                         realfcn(vmax),imagfcn(vmax)); \
     311                        creal(vmax),cimag(vmax)); \
     312                break; \
    310313            } \
    311314            for (unsigned int row = 0;row<numRows;row++) { \
     
    313316                for (unsigned int col = 0; col < numCols; col++) { \
    314317                    if ( (realfcn(inputRow[col]) > realMax) || (imagfcn(inputRow[col]) > imagMax) ) { \
     318                        inputRow[col] = (ps##type)vmax; \
     319                        numClipped++; \
     320                    } else if ( (realfcn(inputRow[col]) < realMin) || (imagfcn(inputRow[col]) < imagMin) ){ \
    315321                        inputRow[col] = (ps##type)vmin; \
    316                         numClipped++; \
    317                     } else if ( (realfcn(inputRow[col]) < realMin) || (imagfcn(inputRow[col]) < imagMax) ){ \
    318                         inputRow[col] = (ps##type)vmax; \
    319322                        numClipped++; \
    320323                    } \
  • trunk/psLib/test/image/tst_psImageManip.c

    r1249 r1319  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-07-21 23:38:27 $
     8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-29 01:20:10 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717#include <stdlib.h>
    1818#include <string.h>                    // for memset
     19#include <sys/stat.h>
     20#include <sys/types.h>
    1921
    2022#include "psTest.h"
     
    2426static int testImageClip(void);
    2527static int testImageClipNAN(void);
     28static int testImageClipComplexRegion(void);
    2629static int testImageOverlay(void);
    2730static int testImageRebin(void);
     
    3235                              {testImageClip,571,"psImageClip",0,false},
    3336                              {testImageClipNAN,572,"psImageClipNAN",0,false},
     37                              {testImageClipComplexRegion,673,"psImageClipComplexRegion",0,false},
    3438                              {testImageOverlay,573,"psImageOverlay",0,false},
    3539                              {testImageRebin,559,"psImageRebin",0,false},
     
    287291}
    288292
     293int testImageClipComplexRegion(void)
     294{
     295    psImage* img = NULL;
     296    unsigned int c = 1024;
     297    unsigned int r = 2048;
     298    int numClipped = 0;
     299    int retVal;
     300
     301    psLogMsg(__func__,PS_LOG_INFO,
     302             "psImageClipNaN shall modified pixel values of NaN with a specified value");
     303
     304    /*
     305    1. Create a complex image with a wide range of complex values
     306
     307    2. call psImageClipComplexRegion with min and max where there is at least
     308       2 pixels in the image above) that is:
     309        a) real(p) < real(min) && complex(p) < complex(min),
     310        b) real(p) < real(min) && complex(min) < complex(p) < complex(max)
     311        c) real(min) < real(p) < real(max) && complex(p) < complex(min)
     312        d) real(min) < real(p) < real(max) && complex(min) < complex(p) < complex(max)
     313        e) real(p) > real(max) && complex(min) < complex(p) < complex(max)
     314        f) real(pmin) < real(p) < real(max) && complex(p) > complex(max)
     315        g) real(p) > real(max) && complex(p) > complex(max)
     316        h) real(p) < real(min) && complex(p) > complex(max)
     317        i) real(p) > real(max) && complex(p) < complex(min)
     318
     319    3. verify that All pixels in case (a), (b), and (c) have the value vmin
     320
     321    4. verify that all pixels in case (d) are unchanged from input
     322
     323    5. verify that all pixels in case (e), (f), (g), (h), and (i) have the
     324       value vmax
     325
     326    */
     327
     328    #define testImageClipComplexByType(datatype,MIN,MAX) /* datatype must be complex */ \
     329    /* create image */ \
     330    img = psImageAlloc(c,r,PS_TYPE_##datatype); \
     331    for (unsigned row=0;row<r;row++) { \
     332        ps##datatype* imgRow = img->data.datatype[row]; \
     333        for (unsigned col=0;col<c;col++) { \
     334            imgRow[col] = row+I*col; \
     335        } \
     336    } \
     337    \
     338    retVal = psImageClipComplexRegion(img,MIN,-1.0-1.0*I,MAX,-2.0-2.0*I); \
     339    \
     340    numClipped = 0; \
     341    for (unsigned row=0;row<r;row++) { \
     342        ps##datatype* imgRow = img->data.datatype[row]; \
     343        for (unsigned col=0;col<c;col++) { \
     344            ps##datatype value = (ps##datatype)(row+I*col); \
     345            if ( (row > creal(MAX)) || (col > cimag(MAX)) ) { \
     346                numClipped++; \
     347                value = -2.0-2.0*I; \
     348            } else if ((row < creal(MIN)) || (col < cimag(MIN)) ) { \
     349                numClipped++; \
     350                value = -1.0-1.0*I; \
     351            } \
     352            if (cabs(imgRow[col]-value) > FLT_EPSILON) { \
     353                psError(__func__,"Pixel value is not as expected (%g%+gi vs %g%+gi) at %d,%d", \
     354                        creal(imgRow[col]),cimag(imgRow[col]),creal(value),cimag(value),col,row); \
     355                return 1; \
     356            } \
     357        } \
     358    } \
     359    if (retVal != numClipped) { \
     360        psError(__func__,"Expected %d clips, but got %d", \
     361                numClipped,retVal); \
     362        return 2; \
     363    } \
     364    psFree(img);
     365
     366    complex double min = ((double)r)/5.0+I*((double)c)/4.0;
     367    complex double max = ((double)r)/3.0+I*((double)c)/2.0;
     368
     369    psLogMsg(__func__,PS_LOG_INFO,"Testing clipping at %g%+gi to %g%+gi for psC32",
     370             creal(min),cimag(min),creal(max),cimag(max));
     371
     372    testImageClipComplexByType(C32,min,max);
     373
     374    psLogMsg(__func__,PS_LOG_INFO,"Testing clipping at %g%+gi to %g%+gi for psC64",
     375             creal(min),cimag(min),creal(max),cimag(max));
     376    testImageClipComplexByType(C64,min,max);
     377
     378    //  6. Call psImageClipComplexRegion with NULL input parameter; should error
     379    //     but not stop execution.
     380
     381    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     382    retVal = psImageClipComplexRegion(NULL,0,0,0,0);
     383    if (retVal != 0) {
     384        psError(__func__,"Expected zero return for clips of a NULL image.");
     385        return 3;
     386    }
     387
     388
     389    img = psImageAlloc(c,r,PS_TYPE_C32);
     390    for (unsigned row=0;row<r;row++) {
     391        psC32* imgRow = img->data.C32[row];
     392        for (unsigned col=0;col<c;col++) {
     393            imgRow[col] = row+I*col;
     394        }
     395    }
     396
     397    //  7. Call psImageClipComplexRegion with min > max; should error and return 0,
     398    //     but not stop execution
     399
     400    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     401    retVal = psImageClipComplexRegion(img,10.0+I*1.0,-1.0,5.0+5.0*I,-2.0);
     402    if (retVal != 0) {
     403        psError(__func__,"Expected zero return for creal(min)>creal(max).");
     404        return 3;
     405    }
     406    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     407    retVal = psImageClipComplexRegion(img,1.0+I*10.0,-1.0,5.0+5.0*I,-2.0);
     408    if (retVal != 0) {
     409        psError(__func__,"Expected zero return for cimag(min)>cimag(max).");
     410        return 3;
     411    }
     412    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     413    retVal = psImageClipComplexRegion(img,10.0+I*10.0,-1.0,5.0+5.0*I,-2.0);
     414    if (retVal != 0) {
     415        psError(__func__,"Expected zero return for min>max.");
     416        return 3;
     417    }
     418
     419    //  8. Call psImageClipComplexRegion with the follow vmin/vmax values; each
     420    //     should error and return 0, but not stop execution
     421    //      a) vmin < datatype region's minimum
     422    //      b) vmax < datatype region's minimum
     423    //      c) vmin > datatype region's maximum
     424    //      d) vmax > datatype region's maximum
     425
     426    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     427    retVal = psImageClipComplexRegion(img,
     428                                      1.0+I*1.0,
     429                                      -2.0*(double)FLT_MAX,
     430                                      5.0+5.0*I,
     431                                      0.0);
     432    if (retVal != 0) {
     433        psError(__func__,"Expected zero return for vmin not in datatype range.");
     434        return 80;
     435    }
     436
     437    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     438    retVal = psImageClipComplexRegion(img,
     439                                      1.0+I*1.0,
     440                                      2.0*(double)FLT_MAX,
     441                                      5.0+5.0*I,
     442                                      0.0);
     443    if (retVal != 0) {
     444        psError(__func__,"Expected zero return for vmin not in datatype range.");
     445        return 81;
     446    }
     447
     448    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     449    retVal = psImageClipComplexRegion(img,
     450                                      1.0+I*1.0,
     451                                      -2.0*(double)FLT_MAX*I,
     452                                      5.0+5.0*I,
     453                                      0.0);
     454    if (retVal != 0) {
     455        psError(__func__,"Expected zero return for vmin not in datatype range.");
     456        return 82;
     457    }
     458
     459    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     460    retVal = psImageClipComplexRegion(img,
     461                                      1.0+I*1.0,
     462                                      2.0*(double)FLT_MAX*I,
     463                                      5.0+5.0*I,
     464                                      0.0);
     465    if (retVal != 0) {
     466        psError(__func__,"Expected zero return for vmin not in datatype range.");
     467        return 83;
     468    }
     469
     470    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     471    retVal = psImageClipComplexRegion(img,
     472                                      1.0+I*1.0,
     473                                      0.0,
     474                                      5.0+5.0*I,
     475                                      -2.0*(double)FLT_MAX);
     476    if (retVal != 0) {
     477        psError(__func__,"Expected zero return for vmax not in datatype range.");
     478        return 84;
     479    }
     480
     481    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     482    retVal = psImageClipComplexRegion(img,
     483                                      1.0+I*1.0,
     484                                      0.0,
     485                                      5.0+5.0*I,
     486                                      2.0*(double)FLT_MAX);
     487    if (retVal != 0) {
     488        psError(__func__,"Expected zero return for vmax not in datatype range.");
     489        return 85;
     490    }
     491
     492    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     493    retVal = psImageClipComplexRegion(img,
     494                                      1.0+I*1.0,
     495                                      0.0,
     496                                      5.0+5.0*I,
     497                                      -2.0*(double)FLT_MAX*I);
     498    if (retVal != 0) {
     499        psError(__func__,"Expected zero return for vmax not in datatype range.");
     500        return 87;
     501    }
     502
     503    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error:");
     504    retVal = psImageClipComplexRegion(img,
     505                                      1.0+I*1.0,
     506                                      0.0,
     507                                      5.0+5.0*I,
     508                                      2.0*(double)FLT_MAX*I);
     509    if (retVal != 0) {
     510        psError(__func__,"Expected zero return for vmax not in datatype range.");
     511        return 88;
     512    }
     513
     514
     515    // now check if vmin > vmax is OK
     516    for (unsigned row=0;row<r;row++) {
     517        psC32* imgRow = img->data.C32[row];
     518        for (unsigned col=0;col<c;col++) {
     519            imgRow[col] = row+I*col;
     520        }
     521    }
     522    retVal = psImageClipComplexRegion(img,
     523                                      1.0+I*1.0,
     524                                      10.0,
     525                                      5.0+5.0*I,
     526                                      0.0);
     527    if (retVal == 0) {
     528        psError(__func__,"Didn't expect zero return for vmin > vmax.");
     529        return 83;
     530    }
     531
     532
     533    psFree(img);
     534    img = NULL;
     535
     536    //  9. Call psImageClipComplexRegion with the max value out of datatype's
     537    //     range; should clip as expected (see step 1-5). Repeat with min value
     538    //     out of datatype's range.
     539
     540    testImageClipComplexByType(C32,-(double)FLT_MAX*2.0-I*(double)FLT_MAX*2.0,10.0+I*10.0);
     541    testImageClipComplexByType(C32,10.0+I*10.0,(double)FLT_MAX*2.0+I*(double)FLT_MAX*2.0);
     542
     543    return 0;
     544}
     545
    289546int testImageOverlay(void)
    290547{
     
    8581115
    8591116    // write results of various rotates to a file and verify with truth images
     1117    mkdir("temp",0777);
    8601118    remove
    8611119        ("temp/fOut.fits");
     
    8741132        }
    8751133        sOut = psImageRotate(sOut,sImg,rot,-1.0,PS_INTERPOLATE_FLAT);
    876         psImageWriteSection(fOut,0,0,0,NULL,index,"temp/fOut.fits");
    877         psImageWriteSection(sOut,0,0,0,NULL,index,"temp/sOut.fits");
     1134        if (! psImageWriteSection(fOut,0,0,0,NULL,index,"temp/fOut.fits") ) {
     1135            psError(__func__,"Can not write to temp/fOut.fits, so why continue!?");
     1136            return 20;
     1137        }
     1138        if (! psImageWriteSection(sOut,0,0,0,NULL,index,"temp/sOut.fits") ) {
     1139            psError(__func__,"Can not write to temp/sOut.fits, so why continue!?");
     1140            return 21;
     1141        }
    8781142
    8791143        // now, let's compare this with the verified file
Note: See TracChangeset for help on using the changeset viewer.