IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2093


Ignore:
Timestamp:
Oct 13, 2004, 1:34:58 PM (22 years ago)
Author:
desonia
Message:

added test for psImageRadialCut.

Location:
trunk/psLib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImageErrors.dat

    r1983 r2093  
    3030psImage_LINE_NOT_IN_IMAGE              Specified line, (%f,%f)->(%f,%f), does not entirely lie in psImage's boundaries, [0:%d,0:%d].
    3131psImage_RADII_VECTOR_NULL              Specified radii vector can not be NULL.
    32 psImage_CENTER_NOT_IN_IMAGE            Specified center, (%d,%d), is outside of the psImage boundaries, [0:%d,0:%d].
     32psImage_CENTER_NOT_IN_IMAGE            Specified center, (%g,%g), is outside of the psImage boundaries, [0:%d,0:%d].
    3333psImage_RADII_VECTOR_TOOSMALL          Input radii vector size, %d, can not be less than 2.
    3434#
  • trunk/psLib/src/image/psImageErrors.h

    r1983 r2093  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-06 21:31:30 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-13 23:34:57 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5252#define PS_ERRORTEXT_psImage_LINE_NOT_IN_IMAGE "Specified line, (%f,%f)->(%f,%f), does not entirely lie in psImage's boundaries, [0:%d,0:%d]."
    5353#define PS_ERRORTEXT_psImage_RADII_VECTOR_NULL "Specified radii vector can not be NULL."
    54 #define PS_ERRORTEXT_psImage_CENTER_NOT_IN_IMAGE "Specified center, (%d,%d), is outside of the psImage boundaries, [0:%d,0:%d]."
     54#define PS_ERRORTEXT_psImage_CENTER_NOT_IN_IMAGE "Specified center, (%g,%g), is outside of the psImage boundaries, [0:%d,0:%d]."
    5555#define PS_ERRORTEXT_psImage_RADII_VECTOR_TOOSMALL "Input radii vector size, %d, can not be less than 2."
    5656#define PS_ERRORTEXT_psImageFFT_IMAGE_TYPE_UNSUPPORTED "Input psImage type (%s) is not supported. Valid image types are psF32 and psC32."
  • trunk/psLib/src/image/psImageExtraction.c

    r2088 r2093  
    99 *  @author Robert DeSonia, MHPCC
    1010 *
    11  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-10-13 22:05:03 $
     11 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-10-13 23:34:57 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    656656        if (numRows != mask->numRows || numCols != mask->numCols) {
    657657            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRadialCut",
    658                        PS_ERR_BAD_PARAMETER_VALUE, true,
     658                       PS_ERR_BAD_PARAMETER_SIZE, true,
    659659                       PS_ERRORTEXT_psImage_IMAGE_MASK_SIZE,
    660660                       mask->numCols,mask->numRows,
    661661                       numCols, numRows);
    662662            psFree(out);
     663            return NULL;
    663664        }
    664665        if (mask->type.type != PS_TYPE_MASK) {
     
    670671                       typeStr, PS_TYPE_MASK_NAME);
    671672            psFree(out);
     673            return NULL;
    672674        }
    673675    }
     
    679681                   PS_ERRORTEXT_psImage_CENTER_NOT_IN_IMAGE,
    680682                   centerCol, centerRow,
    681                    numCols, numRows);
    682         psFree(out);
     683                   numCols-1, numRows-1);
     684        psFree(out);
     685        return NULL;
    683686    }
    684687
     
    693696    if (radii->n < 2) {
    694697        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRadialCut",
    695                    PS_ERR_BAD_PARAMETER_VALUE, true,
     698                   PS_ERR_BAD_PARAMETER_SIZE, true,
    696699                   PS_ERRORTEXT_psImage_RADII_VECTOR_TOOSMALL,
    697700                   radii->n);
     
    713716        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRadialCut",
    714717                   PS_ERR_BAD_PARAMETER_VALUE, false,
    715                    PS_ERRORTEXT_psImage_BAD_STAT);
     718                   PS_ERRORTEXT_psImage_BAD_STAT,
     719                   stats->options);
    716720        psFree(out);
    717721        return NULL;
     
    725729    psF64* outData = out->data.F64;
    726730
    727     // sort the radii by value
    728731    psVector* rSqVec = psVectorCopy(NULL, radii, PS_TYPE_F32);
    729     psVectorSort(rSqVec,rSqVec);
    730732    psF32* rSq = rSqVec->data.F32;
    731733
     
    751753    }
    752754
    753     // Square the data
     755    // Square the radii data
    754756    for (int d = 0; d <= numOut; d++) {
    755757        rSq[d] *= rSq[d];
     
    787789            dY = centerRow - (float)row - 0.5f;
    788790            dist = dX*dX+dY*dY;
    789             for (int r = 0; r < numOut;) {
    790                 if (rSq[r] < dist && dist < rSq[++r]) {
     791            for (int r = 0; r < numOut; r++) {
     792                if (rSq[r] < dist && dist < rSq[r+1]) {
    791793                    int n = buffer[r]->n;
    792794                    if (n == buffer[r]->nalloc) { // in case buffers already full, expand
     
    828830    psFree(buffer);
    829831    psFree(bufferMask);
    830 
     832    psFree(rSqVec);
    831833    return out;
    832834}
  • trunk/psLib/test/image/tst_psImageExtraction.c

    r2087 r2093  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2004-10-13 22:04:29 $
     8*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2004-10-13 23:34:58 $
    1010*
    1111*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    10101010static int testImageCut(void)
    10111011{
    1012     // XXX - fill in
    10131012    int c = 300;
    10141013    int r = 200;
     
    11741173static int testImageRadialCut(void)
    11751174{
    1176     // XXX - fill in
     1175    int c = 300;
     1176    int r = 200;
     1177    int centerX = c/2;
     1178    int centerY = r/2;
     1179    psErr* err = NULL;
     1180
     1181    psImage* image = psImageAlloc(c,r,PS_TYPE_F32);
     1182    psImage* mask = psImageAlloc(c,r,PS_TYPE_MASK);
     1183    for (int row = 0; row < image->numRows; row++) {
     1184        for (int col = 0; col < image->numCols; col++) {
     1185            image->data.F32[row][col] = sqrtf((col-centerX)*(col-centerX)+(row-centerY)*(row-centerY));
     1186            if ((row & 0x0F) == 0) {
     1187                mask->data.PS_TYPE_MASK_DATA[row][col] = 1;
     1188            } else {
     1189                mask->data.PS_TYPE_MASK_DATA[row][col] = 0;
     1190            }
     1191        }
     1192    }
     1193
     1194    psStats* stat = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
     1195    psVector* radii = psVectorAlloc(10,PS_TYPE_F32);
     1196    for (int i=0; i < 10; i++) {
     1197        radii->data.F32[i] = 10+i*10;
     1198    }
     1199
     1200    psVector* result = NULL;
     1201
     1202    result = psImageRadialCut(result,image,mask,1,centerX,centerY,radii,stat);
     1203
     1204    if (result == NULL) {
     1205        psLogMsg(__func__,PS_LOG_ERROR,
     1206                 "Return value of NULL unexpected.");
     1207        return 1;
     1208    }
     1209
     1210    if (result->type.type != PS_TYPE_F64) {
     1211        psLogMsg(__func__,PS_LOG_ERROR,
     1212                 "Return type not psF64, as expected.");
     1213        return 2;
     1214    }
     1215
     1216    for (int i=0; i < 9; i++) {
     1217        if (fabs(result->data.F64[i] - (15.0+i*10)) > 1) {
     1218            psLogMsg(__func__,PS_LOG_ERROR,
     1219                     "Result was not as expected for radii #%d (%g, expected %d +/- 1)",
     1220                     result->data.F64[i], (15.0+i*10) );
     1221            return 3+i;
     1222        }
     1223    }
     1224
     1225    // again, but without mask
     1226    psVector* orig = result;
     1227    result = psImageRadialCut(result,image,NULL,1,centerX,centerY,radii,stat);
     1228
     1229    if (result == NULL) {
     1230        psLogMsg(__func__,PS_LOG_ERROR,
     1231                 "Return value of NULL unexpected.");
     1232        return 12;
     1233    }
     1234
     1235    if (result != orig) {
     1236        psLogMsg(__func__,PS_LOG_ERROR,
     1237                 "Return value of is not same as input parameter 'out'.");
     1238        return 13;
     1239    }
     1240
     1241    for (int i=0; i < 9; i++) {
     1242        if (fabs(result->data.F64[i] - (15.0+i*10)) > 1) {
     1243            psLogMsg(__func__,PS_LOG_ERROR,
     1244                     "Result was not as expected for radii #%d (%g, expected %d +/- 1)",
     1245                     result->data.F64[i], (15.0+i*10) );
     1246            return 14+i;
     1247        }
     1248    }
     1249
     1250    // NULL input image...
     1251    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1252    result = psImageRadialCut(result,NULL,NULL,1,centerX,centerY,radii,stat);
     1253
     1254    if (result != NULL) {
     1255        psLogMsg(__func__,PS_LOG_ERROR,
     1256                 "Return value not NULL as expected.");
     1257        return 23;
     1258    }
     1259
     1260    err = psErrorLast();
     1261    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
     1262        psLogMsg(__func__,PS_LOG_ERROR,
     1263                 "psImageRadialCut did not generate proper error message.");
     1264        return 24;
     1265    }
     1266    psFree(err);
     1267
     1268    // NULL input radii...
     1269    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1270    result = psImageRadialCut(result,image,mask,1,centerX,centerY,NULL,stat);
     1271
     1272    if (result != NULL) {
     1273        psLogMsg(__func__,PS_LOG_ERROR,
     1274                 "Return value not NULL as expected.");
     1275        return 23;
     1276    }
     1277
     1278    err = psErrorLast();
     1279    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
     1280        psLogMsg(__func__,PS_LOG_ERROR,
     1281                 "psImageRadialCut did not generate proper error message.");
     1282        return 24;
     1283    }
     1284    psFree(err);
     1285
     1286    // NULL input stat...
     1287    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1288    result = psImageRadialCut(result,image,mask,1,centerX,centerY,radii,NULL);
     1289
     1290    if (result != NULL) {
     1291        psLogMsg(__func__,PS_LOG_ERROR,
     1292                 "Return value not NULL as expected.");
     1293        return 23;
     1294    }
     1295
     1296    err = psErrorLast();
     1297    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
     1298        psLogMsg(__func__,PS_LOG_ERROR,
     1299                 "psImageRadialCut did not generate proper error message.");
     1300        return 24;
     1301    }
     1302    psFree(err);
     1303
     1304    // Bad center X
     1305    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1306    result = psImageRadialCut(result,image,mask,1,
     1307                              c+1,centerY,radii,stat);
     1308
     1309    if (result != NULL) {
     1310        psLogMsg(__func__,PS_LOG_ERROR,
     1311                 "Return value not NULL as expected.");
     1312        return 25;
     1313    }
     1314
     1315    err = psErrorLast();
     1316    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1317        psLogMsg(__func__,PS_LOG_ERROR,
     1318                 "psImageRadialCut did not generate proper error message.");
     1319        return 26;
     1320    }
     1321    psFree(err);
     1322
     1323    // Bad center Y
     1324    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1325    result = psImageRadialCut(result,image,mask,1,
     1326                              centerX,r+1,radii,stat);
     1327
     1328    if (result != NULL) {
     1329        psLogMsg(__func__,PS_LOG_ERROR,
     1330                 "Return value not NULL as expected.");
     1331        return 27;
     1332    }
     1333
     1334    err = psErrorLast();
     1335    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1336        psLogMsg(__func__,PS_LOG_ERROR,
     1337                 "psImageRadialCut did not generate proper error message.");
     1338        return 28;
     1339    }
     1340    psFree(err);
     1341
     1342    // Bad mask type (N.B., swapped image/mask to do this)
     1343    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1344    result = psImageRadialCut(result,mask,image,1,
     1345                              centerX,r+1,radii,stat);
     1346
     1347    if (result != NULL) {
     1348        psLogMsg(__func__,PS_LOG_ERROR,
     1349                 "Return value not NULL as expected.");
     1350        return 29;
     1351    }
     1352
     1353    err = psErrorLast();
     1354    if (err->code != PS_ERR_BAD_PARAMETER_TYPE) {
     1355        psLogMsg(__func__,PS_LOG_ERROR,
     1356                 "psImageRadialCut did not generate proper error message.");
     1357        return 30;
     1358    }
     1359    psFree(err);
     1360
     1361    // Bad mask size
     1362    psImage* mask2 = psImageAlloc(c/2,r/2,PS_TYPE_MASK);
     1363    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1364    result = psImageRadialCut(result,image, mask2, 1,
     1365                              centerX,centerY,radii,stat);
     1366    psFree(mask2);
     1367    if (result != NULL) {
     1368        psLogMsg(__func__,PS_LOG_ERROR,
     1369                 "Return value not NULL as expected.");
     1370        return 31;
     1371    }
     1372
     1373    err = psErrorLast();
     1374    if (err->code != PS_ERR_BAD_PARAMETER_SIZE) {
     1375        psLogMsg(__func__,PS_LOG_ERROR,
     1376                 "psImageRadialCut did not generate proper error message.");
     1377        return 32;
     1378    }
     1379    psFree(err);
     1380
     1381    // Bad radii size
     1382    psVector* radii2 = psVectorAlloc(1,PS_TYPE_MASK);
     1383    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1384    result = psImageRadialCut(result,image, mask, 1,
     1385                              centerX,centerY,radii2,stat);
     1386    psFree(radii2);
     1387    if (result != NULL) {
     1388        psLogMsg(__func__,PS_LOG_ERROR,
     1389                 "Return value not NULL as expected.");
     1390        return 33;
     1391    }
     1392
     1393    err = psErrorLast();
     1394    if (err->code != PS_ERR_BAD_PARAMETER_SIZE) {
     1395        psLogMsg(__func__,PS_LOG_ERROR,
     1396                 "psImageRadialCut did not generate proper error message.");
     1397        return 34;
     1398    }
     1399    psFree(err);
     1400
     1401    // bad input stat option...
     1402    stat->options = 0;
     1403    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     1404    result = psImageRadialCut(result,image,mask,1,centerX,centerY,radii,stat);
     1405    stat->options = PS_STAT_SAMPLE_MEAN;
     1406
     1407    if (result != NULL) {
     1408        psLogMsg(__func__,PS_LOG_ERROR,
     1409                 "Return value not NULL as expected.");
     1410        return 35;
     1411    }
     1412
     1413    err = psErrorLast();
     1414    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
     1415        psLogMsg(__func__,PS_LOG_ERROR,
     1416                 "psImageRadialCut did not generate proper error message.");
     1417        return 36;
     1418    }
     1419    psFree(err);
     1420
     1421    psFree(image);
     1422    psFree(mask);
     1423    psFree(radii);
     1424    psFree(stat);
     1425    psFree(result);
    11771426
    11781427    return 0;
Note: See TracChangeset for help on using the changeset viewer.