Changeset 1404 for trunk/psLib/test/image/tst_psImageExtraction.c
- Timestamp:
- Aug 6, 2004, 11:50:14 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageExtraction.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageExtraction.c
r1364 r1404 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-08-0 2 18:30:10$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-08-06 21:50:14 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 27 } 28 28 }; 29 29 30 30 int main( int argc, char* argv[] ) 31 31 { … … 41 41 psVector* out = NULL; 42 42 psImage* image = psImageAlloc( c, r, PS_TYPE_F32 ); 43 psVector* positions = psVectorAlloc( r, PS_TYPE_U32 ); 43 44 psImage* mask = psImageAlloc( c, r, PS_TYPE_MASK ); 44 45 psStats* stat = psStatsAlloc( PS_STAT_SAMPLE_MEDIAN ); 45 46 46 47 /* 47 48 This function shall extract pixels from a specified region of a psImage 48 49 structure into a vector using a specified statistical method. 49 50 50 51 Verify the returned psVector structure contains expected data, if the 51 52 input psImage input has known data and the psStats structure specifies … … 57 58 58 59 */ 59 60 60 61 for ( int row = 0;row < r;row++ ) { 61 psF32* imageRow = image->data.F32[ row ]; 62 psMaskType* maskRow = image->data.V[ row ]; 63 psF32 rowOffset = ( psF32 ) row / ( psF32 ) r; 64 for ( int col = 0;col < c;col++ ) { 65 imageRow[ col ] = ( psF32 ) col + rowOffset; 66 maskRow[ col ] = 0; 67 } 62 psF32* imageRow = image->data.F32[ row ]; 63 psMaskType* maskRow = image->data.V[ row ]; 64 psF32 rowOffset = ( psF32 ) row / ( psF32 ) r; 65 for ( int col = 0;col < c;col++ ) { 66 imageRow[ col ] = ( psF32 ) col + rowOffset; 67 maskRow[ col ] = 0; 68 68 } 69 69 } 70 70 71 // test MxN case 71 72 72 73 #define PSIMAGESLICE_TEST1(M,N,DIRECTION,TRUTH_SIZE,TRUTHPIX_X,TRUTHPIX_Y,TESTNUM) \ 73 out = psImageSlice(out, image,mask,1,c/10,r/10,M,N,DIRECTION,stat); \74 out = psImageSlice(out,positions,image,mask,1,c/10,r/10,M,N,DIRECTION,stat); \ 74 75 \ 75 76 if (out->n != TRUTH_SIZE) { \ 76 psError(__func__,"Number of results is wrong (%d, not %d)", \ 77 out->n,n); \ 78 return TESTNUM*2+1; \ 79 } \ 77 psError(__func__,"Number of results is wrong (%d, not %d)", \ 78 out->n,n); \ 79 return TESTNUM*4+1; \ 80 } \ 81 \ 82 if (positions->n != TRUTH_SIZE) { \ 83 psError(__func__,"Number of results for positions vector is wrong (%d, not %d)", \ 84 out->n,n); \ 85 return TESTNUM*4+2; \ 86 } \ 80 87 \ 81 88 for (int i=0;i<out->n;i++) { \ 82 if (abs(out->data.F64[i]-image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]) > 1.0/(psF32)r) { \ 83 psError(__func__,"Improper result at position %d.",i); \ 84 return TESTNUM*2+2; \ 85 } \ 86 } 87 89 if (abs(out->data.F64[i]-image->data.F32[r/10+TRUTHPIX_Y][c/10+TRUTHPIX_X]) > 1.0/(psF32)r) { \ 90 psError(__func__,"Improper result at position %d.",i); \ 91 return TESTNUM*4+3; \ 92 } \ 93 if (DIRECTION == PS_CUT_X_POS || DIRECTION == PS_CUT_X_NEG) { \ 94 if (positions->data.U32[i] != c/10+TRUTHPIX_X) { \ 95 psError(__func__,"Improper postions result @ %d.",i); \ 96 return TESTNUM*4+4; \ 97 } \ 98 } else { \ 99 if (positions->data.U32[i] != r/10+TRUTHPIX_Y) { \ 100 psError(__func__,"Improper postions result @ %d.",i); \ 101 return TESTNUM*4+4; \ 102 } \ 103 } \ 104 } 105 88 106 // test MxN case 89 107 PSIMAGESLICE_TEST1( m, n, PS_CUT_X_POS, m, i, n / 2, 0 ); … … 91 109 PSIMAGESLICE_TEST1( m, n, PS_CUT_Y_POS, n, m / 2, i, 2 ); 92 110 PSIMAGESLICE_TEST1( m, n, PS_CUT_Y_NEG, n, m / 2, n - 1 - i, 3 ); 93 111 94 112 // test Mx1 case 95 113 PSIMAGESLICE_TEST1( m, 1, PS_CUT_X_POS, m, i, 0, 4 ); … … 97 115 PSIMAGESLICE_TEST1( m, 1, PS_CUT_Y_POS, 1, m / 2, 0, 6 ); 98 116 PSIMAGESLICE_TEST1( m, 1, PS_CUT_Y_NEG, 1, m / 2, 0, 7 ); 99 117 100 118 // test 1xN case 101 119 PSIMAGESLICE_TEST1( 1, n, PS_CUT_X_POS, 1, 0, n / 2, 8 ); … … 103 121 PSIMAGESLICE_TEST1( 1, n, PS_CUT_Y_POS, n, 0, n - 1 - i, 10 ); 104 122 PSIMAGESLICE_TEST1( 1, n, PS_CUT_Y_NEG, n, 0, n - 1 - i, 11 ); 105 123 106 124 // test 1x1 case 107 125 PSIMAGESLICE_TEST1( 1, 1, PS_CUT_X_POS, 1, 0, 0, 12 ); … … 109 127 PSIMAGESLICE_TEST1( 1, 1, PS_CUT_Y_POS, 1, 0, 0, 14 ); 110 128 PSIMAGESLICE_TEST1( 1, 1, PS_CUT_Y_NEG, 1, 0, 0, 15 ); 111 129 112 130 /* 113 131 Verify the returned psVector structure pointer is null and program 114 132 execution doesn't stop, if input psImage input is null. 115 116 */ 117 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 118 out = psImageSlice( out, NULL, NULL, 0, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat );119 if ( out != NULL ) { 120 psError( __func__, "Giving a NULL image, psImageSlice didn't return NULL as expected" );121 return 41;122 }123 124 133 134 */ 135 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 136 out = psImageSlice( out, NULL, NULL, NULL, 0, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat ); 137 if ( out != NULL ) { 138 psError( __func__, "Giving a NULL image, psImageSlice didn't return NULL as expected" ); 139 return 101; 140 } 141 142 125 143 /* 126 144 Verify the returned psVector structure pointer is null and program … … 128 146 */ 129 147 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 130 out = psImageSlice( out, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, NULL );131 if ( out != NULL ) { 132 psError( __func__, "Giving a NULL stat struct, psImageSlice didn't return NULL as expected" );133 return 42;134 }135 136 /* 137 148 out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, NULL ); 149 if ( out != NULL ) { 150 psError( __func__, "Giving a NULL stat struct, psImageSlice didn't return NULL as expected" ); 151 return 102; 152 } 153 154 /* 155 138 156 Verify the returned psVector structure pointer is null and program 139 157 executions doesn't stop, if the input direction is not set to one of … … 141 159 */ 142 160 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 143 out = psImageSlice( out, image, mask, 1, c / 10, r / 10, 1, 1, 5, stat );144 if ( out != NULL ) { 145 psError( __func__, "Giving a bogus direction flag, psImageSlice didn't return NULL as expected" );146 return 43;147 }148 161 out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, 5, stat ); 162 if ( out != NULL ) { 163 psError( __func__, "Giving a bogus direction flag, psImageSlice didn't return NULL as expected" ); 164 return 103; 165 } 166 149 167 /* 150 168 Verify the returned psVector structure pointer is null and program … … 152 170 */ 153 171 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 154 out = psImageSlice( out, image, mask, 1, c / 10, r / 10, 0, 0, PS_CUT_X_POS, stat );155 if ( out != NULL ) { 156 psError( __func__, "Giving a 0x0 region, psImageSlice didn't return NULL as expected" );157 return 44;158 }159 172 out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 0, 0, PS_CUT_X_POS, stat ); 173 if ( out != NULL ) { 174 psError( __func__, "Giving a 0x0 region, psImageSlice didn't return NULL as expected" ); 175 return 104; 176 } 177 160 178 /* 161 179 Verify the returned psVector structure pointer is null and program … … 164 182 */ 165 183 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 166 out = psImageSlice( out, image, mask, 1, c + 1, r / 10, 1, 1, PS_CUT_X_POS, stat );167 if ( out != NULL ) { 168 psError( __func__, "Giving an invalid x position, psImageSlice didn't return NULL as expected" );169 return 45;170 }171 172 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 173 out = psImageSlice( out, image, mask, 1, c / 10, r + 1, 1, 1, PS_CUT_X_POS, stat );174 if ( out != NULL ) { 175 psError( __func__, "Giving an invalid y position, psImageSlice didn't return NULL as expected" );176 return 46;177 }178 179 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 180 out = psImageSlice( out, image, mask, 1, c / 10, r / 10, c, 1, PS_CUT_X_POS, stat );181 if ( out != NULL ) { 182 psError( __func__, "Giving an invalid numCols, psImageSlice didn't return NULL as expected" );183 return 47;184 }185 186 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 187 out = psImageSlice( out, image, mask, 1, c / 10, r / 10, 1, r, PS_CUT_X_POS, stat );188 if ( out != NULL ) { 189 psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" );190 return 48;191 }192 184 out = psImageSlice( out, NULL, image, mask, 1, c + 1, r / 10, 1, 1, PS_CUT_X_POS, stat ); 185 if ( out != NULL ) { 186 psError( __func__, "Giving an invalid x position, psImageSlice didn't return NULL as expected" ); 187 return 105; 188 } 189 190 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 191 out = psImageSlice( out, NULL, image, mask, 1, c / 10, r + 1, 1, 1, PS_CUT_X_POS, stat ); 192 if ( out != NULL ) { 193 psError( __func__, "Giving an invalid y position, psImageSlice didn't return NULL as expected" ); 194 return 106; 195 } 196 197 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 198 out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, c, 1, PS_CUT_X_POS, stat ); 199 if ( out != NULL ) { 200 psError( __func__, "Giving an invalid numCols, psImageSlice didn't return NULL as expected" ); 201 return 107; 202 } 203 204 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 205 out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, r, PS_CUT_X_POS, stat ); 206 if ( out != NULL ) { 207 psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" ); 208 return 108; 209 } 210 193 211 /* 194 212 Verify the returned psVector structure pointer is null and program … … 198 216 psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." ); 199 217 stat->options = 0; 200 out = psImageSlice( out, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat );201 if ( out != NULL ) { 202 psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" );203 return 49;204 }205 218 out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat ); 219 if ( out != NULL ) { 220 psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" ); 221 return 109; 222 } 223 206 224 psFree( image ); 225 psFree( positions ); 207 226 psFree( mask ); 208 227 psFree( out ); 209 228 psFree( stat ); 210 229 211 230 return 0; 212 231 213 232 } 214 233 215 216 217 218 219 220 221
Note:
See TracChangeset
for help on using the changeset viewer.
