Array * MedianFilter(RasterizedImage & img, ParaSet & imgPara, Array *original, int filterRadius){ // output image Array *median = Make_Array_With_Shape(PLAIN_KIND,UINT32_TYPE,Coord2(original->dims[1], original->dims[0])); uint32 *med = AUINT32(median); uint32 *orig = AUINT32(original); #ifdef DEVELOP Array *variance = Make_Array_With_Shape(PLAIN_KIND,UINT32_TYPE,Coord2(original->dims[1], original->dims[0])); uint32 *var = AUINT32(variance); #endif Use_Reflective_Boundary(); // frames defines the local neighborhood Frame * f = Make_Frame(original,Coord2(2*filterRadius+1,2*filterRadius+1),Coord2(filterRadius,filterRadius)); Histogram * h = Make_Histogram(UVAL,img.GetDepth(),ValU(1),ValU(0)); Place_Frame(f,0); for (Indx_Type p = 0; p < median->size; p++){ Empty_Histogram(h); Histagain_Array(h,f,0); h->counts[orig[p]]--; // excludes the height of p in the calculation of the median med[p] = Percentile2Bin(h,.5); // median is given at 50th percentile #ifdef DEVELOP var[p] = 10*Histogram_Sigma(h); #endif Move_Frame_Forward(f); } Kill_Histogram(h); Kill_Frame(f); #ifdef DEVELOP ShowArray(img, imgPara, "median.tif", median); ShowArray(img, imgPara, "variance.tif", variance); Free_Array(variance); #endif if (imgPara.verbose){ std::cout << "Planes filtered" << std::endl; } return (median); }
int main() { int a[6]; /* 乱数初期化 */ srand((unsigned)time(NULL)); ShowArray(a); printf("\n"); TwiceTimes(a); getchar(); return 0; }
Array * Filtering_Confidence (RasterizedImage & img, ParaSet & imgPara, Array * original, int filterRadii [], double threshold, Array * confidence) { Array * median = Copy_Array(original); // iterate through the list of radii and filter the image for (int i=0; i < sizeof(filterRadii)/sizeof(*filterRadii); i++) { Free_Array(median); median = LocalMedianFilter_Confidence(img, imgPara, original, filterRadii[i], threshold, confidence); Free_Array(original); original = Copy_Array(median); } #ifdef DEVELOP ShowArray(img, imgPara, "median.tif",median); #endif if (imgPara.verbose){ std::cout << "Planes filtered" << std::endl; } return median; }
void main ( int argc, char *argv[] ) { Element **Array; int Items = 2000; if ( argc != 2 && argc != 3 ) { fprintf ( stderr, "Usage: quick1 infile [maxitems]\n" ); return; } if ( argc == 3 ) Items = atoi ( argv[2] ); if (( Items = LoadArray ( argv[1], Items, &Array )) == -1 ) return; /* Couldn't load file */ QuickSort1 ( Array, Items, (CompFunc) Cfunc ); ShowArray ( Array, Items, (CompFunc) Cfunc ); }
/////////////////////////////// QuickSortNR ///////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// void QuickSortNR( zULONG ulRecord1, // non-recursive zULONG ulRecord2 ) { ASSERT_TRACE( "QuickSort argument error", 0, ulRecord1 <= ulRecord2 ); zULONG m = ulRecord2 - ulRecord1; zULONG ulStackSize = 2; while ( m >>= 1 ) { ulStackSize++; } ulStackSize <<= 2; // two entries for each comparison zPULONG pulStack = (zPULONG) m_pPoolVarData->Alloc( ulStackSize * sizeof( zULONG ) ); zULONG ulStack = 0; zULONG uLeft; zULONG uRight; #ifdef DEBUG_ALL zULONG ulStackMax = 0; #endif pulStack[ ulStack++ ] = ulRecord1; pulStack[ ulStack++ ] = ulRecord2; while ( ulStack ) { uRight = pulStack[ --ulStack ]; uLeft = pulStack[ --ulStack ]; m = QuickSortPartition( uLeft, uRight ); #ifdef DEBUG_ALL ShowArray( uLeft, uRight ); #endif if ( m + 1 < uRight ) { #ifdef DEBUG_ALL if ( ulStack > ulStackSize - 2 ) { ASSERT_TRACE( "QuickSort stack overflow - %d", ulStackSize, FALSE ); m_pPoolVarData->Free( pulStack ); return; } #endif pulStack[ ulStack++ ] = m + 1; pulStack[ ulStack++ ] = uRight; #ifdef DEBUG_ALL if ( ulStack > ulStackMax ) { ulStackMax = ulStack; } #endif } if ( uLeft < m ) { #ifdef DEBUG_ALL if ( ulStack > ulStackSize - 2 ) { ASSERT_TRACE( "QuickSort stack overflow - %d", ulStackSize, FALSE ); m_pPoolVarData->Free( pulStack ); return; } #endif pulStack[ ulStack++ ] = uLeft; pulStack[ ulStack++ ] = m; #ifdef DEBUG_ALL if ( ulStack > ulStackMax ) { ulStackMax = ulStack; } #endif } } m_pPoolVarData->Free( pulStack ); #ifdef DEBUG_ALL ASSERT_TRACE( "Max stack utilization = %d\tAllocated stacksize = %d", (ulStackMax, ulStackSize), FALSE ); #endif }