Changeset 3723
- Timestamp:
- Apr 19, 2005, 1:44:54 PM (21 years ago)
- Location:
- trunk/psModules
- Files:
-
- 2 edited
-
src/pmObjects.c (modified) (5 diffs)
-
test/tst_pmObjects01.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/pmObjects.c
r3717 r3723 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1. 19$ $Name: not supported by cvs2svn $8 * @date $Date: 2005-04-19 2 2:58:48$7 * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2005-04-19 23:44:54 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 312 312 above the given threshold. Returns a psList containing location (x/y value) 313 313 of all peaks. 314 315 XXX: For multiple type peaks, ensure that each is set. 316 317 XXX: This does not work if image has either a single row, or a single column. 318 *****************************************************************************/ 314 *****************************************************************************/ 319 315 psList *pmFindImagePeaks(const psImage *image, 320 316 psF32 threshold) … … 322 318 PS_IMAGE_CHECK_NULL(image, NULL); 323 319 PS_IMAGE_CHECK_TYPE(image, PS_TYPE_F32, NULL); 324 if ((image->numRows == 1) || (image->numCols == 1)) {325 psError(PS_ERR_UNKNOWN, true, "Currently, input image must have at least 2 rows and 2 columns.");326 }327 320 psPeakType myPeakClass = PM_PEAK_UNDEF; 328 321 psVector *tmpRow = NULL; … … 332 325 333 326 // 334 // Find peaks in row 0 only. 327 // Special case: a 1-by-1 image. 328 // 329 if ((image->numCols == 1) && (image->numRows == 1)) { 330 if (image->data.F32[row][col] > threshold) { 331 myPeakClass = PM_PEAK_EDGE | PM_PEAK_LONE; 332 list = MyListAddPeak(list, 0, 0, image->data.F32[row][col], myPeakClass); 333 return(list); 334 } else { 335 return(NULL); 336 } 337 } 338 339 // 340 // Find peaks in row 0 only (single-row image). This is a special case since 341 // we can not test data at image->data.F32[row+1][...]) 342 // 343 if (image->numRows == 1) { 344 row = 0; 345 tmpRow = p_psGetRowVectorFromImage((psImage *) image, row); 346 psVector *row1 = pmFindVectorPeaks(tmpRow, threshold); 347 for (psU32 i = 0 ; i < row1->n ; i++ ) { 348 col = row1->data.U32[i]; 349 // 350 // Determine if pixel (0,0) is a peak. 351 // 352 if (col == 0) { 353 if ( (image->data.F32[row][col] > threshold) && 354 (image->data.F32[row][col] > image->data.F32[row][col+1])) { 355 myPeakClass = PM_PEAK_EDGE | PM_PEAK_LONE; 356 list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass); 357 } 358 } else if (col < (image->numCols - 1)) { 359 360 if ( (image->data.F32[row][col] > threshold) && 361 (image->data.F32[row][col] >= image->data.F32[row][col-1]) && 362 (image->data.F32[row][col] > image->data.F32[row][col+1])) { 363 myPeakClass = PM_PEAK_EDGE; 364 365 if (image->data.F32[row][col] > image->data.F32[row][col-1]) { 366 myPeakClass|= PM_PEAK_LONE; 367 } else { 368 myPeakClass|= PM_PEAK_FLAT; 369 } 370 list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass); 371 } 372 373 } else if (col == (image->numCols - 1)) { 374 if ( (image->data.F32[row][col] > threshold) && 375 (image->data.F32[row][col] >= image->data.F32[row][col-1])) { 376 myPeakClass = PM_PEAK_EDGE; 377 378 if (image->data.F32[row][col] > image->data.F32[row][col-1]) { 379 myPeakClass|= PM_PEAK_LONE; 380 } else { 381 myPeakClass|= PM_PEAK_FLAT; 382 } 383 list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass); 384 } 385 } else { 386 psError(PS_ERR_UNKNOWN, true, "peak specified outside valid column range."); 387 } 388 389 } 390 // 391 // We exit here since this is a single-row image. 392 // 393 // XXX: Why are we not getting memory leak errors? 394 // 395 // 396 // psFree(tmpRow); 397 // psFree(row1); 398 // 399 return(list); 400 } 401 402 // 403 // Find peaks in col 0 only (single-col image). This is a special case since 404 // we can not test data at image->data.F32[...][col+1]) 405 // 406 if (image->numCols == 1) { 407 col = 0; 408 psVector *tmpCol = p_psGetColVectorFromImage((psImage *) image, col); 409 psVector *col1 = pmFindVectorPeaks(tmpCol, threshold); 410 for (psU32 i = 0 ; i < col1->n ; i++ ) { 411 row = col1->data.U32[i]; 412 // 413 // Determine if pixel (0,0) is a peak. 414 // 415 if (row == 0) { 416 if ( (image->data.F32[row][col] > threshold) && 417 (image->data.F32[row][col] > image->data.F32[row+1][col])) { 418 myPeakClass = PM_PEAK_EDGE | PM_PEAK_LONE; 419 list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass); 420 } 421 } else if (row < (image->numRows - 1)) { 422 423 if ( (image->data.F32[row][col] > threshold) && 424 (image->data.F32[row][col] >= image->data.F32[row-1][col]) && 425 (image->data.F32[row][col] > image->data.F32[row+1][col])) { 426 myPeakClass = PM_PEAK_EDGE; 427 428 if (image->data.F32[row][col] > image->data.F32[row-1][col]) { 429 myPeakClass|= PM_PEAK_LONE; 430 } else { 431 myPeakClass|= PM_PEAK_FLAT; 432 } 433 list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass); 434 } 435 436 } else if (row == (image->numRows - 1)) { 437 if ( (image->data.F32[row][col] > threshold) && 438 (image->data.F32[row][col] >= image->data.F32[row-1][col])) { 439 myPeakClass = PM_PEAK_EDGE; 440 441 if (image->data.F32[row][col] > image->data.F32[row-1][col]) { 442 myPeakClass|= PM_PEAK_LONE; 443 } else { 444 myPeakClass|= PM_PEAK_FLAT; 445 } 446 list = MyListAddPeak(list, col, row, image->data.F32[row][col], myPeakClass); 447 } 448 } else { 449 psError(PS_ERR_UNKNOWN, true, "peak specified outside valid row range."); 450 } 451 452 } 453 // 454 // We exit here since this is a single-column image. 455 // 456 // XXX: free tmpRow col1? 457 // 458 return(list); 459 } 460 461 // 462 // Find peaks in row 0 only (multi-row image). 335 463 // 336 464 row = 0; … … 392 520 psError(PS_ERR_UNKNOWN, true, "peak specified outside valid column range."); 393 521 } 394 }395 //396 // Exit if this image has a single row.397 //398 if (image->numRows == 1) {399 return(list);400 522 } 401 523 -
trunk/psModules/test/tst_pmObjects01.c
r3717 r3723 19 19 * abd never deallocate, no error is generated. 20 20 * 21 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $22 * @date $Date: 2005-04-19 2 2:58:48$21 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2005-04-19 23:44:54 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 479 479 { 480 480 printf("-------------- Calling test_pmFindVectorPeaks on an %d-by-%d image. --------------\n", numRows, numCols); 481 if ((numRows < 4) || (numCols < 4)) {482 printf("WARNING: Don't call this test with a smaller than 4-by-4 image.\n");483 return(true);484 }481 // if ((numRows < 4) || (numCols < 4)) { 482 // printf("WARNING: Don't call this test with a smaller than 4-by-4 image.\n"); 483 // return(true); 484 // } 485 485 bool testStatus = true; 486 486 psImage *inData = psImageAlloc(numCols, numRows, PS_TYPE_F32); … … 523 523 testStatus = false; 524 524 } else { 525 if (outData->size != 5) { 526 printf("TEST ERROR: pmFindImagePeaks found %d peaks (should be 4)\n", outData->size); 527 testStatus = false; 528 } 529 525 psS32 expectedNumPeaks; 526 if ((numRows == 1) && (numCols == 1)) { 527 expectedNumPeaks = 1; 528 } else if ((numRows == 1) || (numCols == 1)) { 529 expectedNumPeaks = 3; 530 } else { 531 expectedNumPeaks = 5; 532 } 533 if (outData->size != expectedNumPeaks) { 534 printf("TEST ERROR: pmFindImagePeaks found %d peaks (should be %d)\n", outData->size, expectedNumPeaks); 535 testStatus = false; 536 } 537 538 // HEY 530 539 psListElem *tmpPeakLE = (psListElem *) outData->head; 531 540 while (tmpPeakLE != NULL) { … … 537 546 if (!(tmpPeak->class & PM_PEAK_LONE) || 538 547 !(tmpPeak->class & PM_PEAK_EDGE)) { 539 printf("TEST ERROR: peak at (%d, %d) (%f) ->class set improperly (0x%x).\n", tmpPeak->y, tmpPeak->x, tmpPeak->counts, tmpPeak->class);548 printf("TEST ERROR: (0) peak at (%d, %d) (%f) ->class set improperly (0x%x).\n", tmpPeak->y, tmpPeak->x, tmpPeak->counts, tmpPeak->class); 540 549 testStatus = false; 541 550 } 542 551 } else if ((tmpPeak->x == numCols/2) && (tmpPeak->y == numRows/2)) { 543 552 if (!(tmpPeak->class & PM_PEAK_LONE)) { 544 printf("TEST ERROR: peak at (%d, %d) (%f) ->class set improperly (0x%x).\n", tmpPeak->y, tmpPeak->x, tmpPeak->counts, tmpPeak->class);553 printf("TEST ERROR: (1) peak at (%d, %d) (%f) ->class set improperly (0x%x).\n", tmpPeak->y, tmpPeak->x, tmpPeak->counts, tmpPeak->class); 545 554 testStatus = false; 546 555 } … … 599 608 // testStatus&= test_pmFindImagePeaks(5, 2); 600 609 // HEY 610 testStatus&= test_pmFindImagePeaks(1, 1); 611 testStatus&= test_pmFindImagePeaks(1, 8); 612 testStatus&= test_pmFindImagePeaks(8, 1); 601 613 testStatus&= test_pmFindImagePeaks(TST02_NUM_ROWS, TST02_NUM_COLS); 602 614 testStatus&= test_pmFindImagePeaks(2*TST02_NUM_ROWS, TST02_NUM_COLS);
Note:
See TracChangeset
for help on using the changeset viewer.
