// // This file is part of the Bones source-to-source compiler examples. This C-code // demonstrates the use of Bones for an example application: 'Speckle Reducing // Anisotropic Diffusion' or 'SRAD', taken from the Rodinia benchmark suite. For // more information on the application or on Bones please use the contact infor- // mation below. // // == More information on SRAD (Speckle Reducing Anisotropic Diffusion): // Article............http://dx.doi.org/10.1109/TIP.2002.804276 // Original code......https://www.cs.virginia.edu/~skadron/wiki/rodinia/ // // == More information on Bones // Contact............Cedric Nugteren // Web address........http://parse.ele.tue.nl/bones/ // // == File information // Filename...........applications/srad.c // Authors............Cedric Nugteren // Original authors...Rob Janiczek, Drew Gilliam, Lukasz Szafaryn // Last modified on...05-Jun-2014 // //######################################################################## // Includes #include "common.h" //######################################################################## //### Start of the main function //######################################################################## int main(void) { // Declare the loop iterators int i,j,iter; // Declare domain variables float mean_roi, var_roi; float q0s, qs; float divergence; float cN, cS, cW, cE; float G2, L; // Declare other/helper variables int index; float temp_value; float sum1, sum2; float current_value; float temp_a, temp_b; // Check for valid row and column sizes if ((ROWS%16 != 0 ) || (COLS%16 != 0)) { printf("[srad] Error: the number of rows and columns must be multiples of 16\n"); fflush(stdout); exit(1); } // Initialising memory printf("\n[srad] Initialising memory"); fflush(stdout); int size = COLS*ROWS; int size_roi = (R2-R1+1)*(C2-C1+1); float values[ROWS][COLS]; float coefficent[ROWS][COLS]; float dN[ROWS][COLS]; float dS[ROWS][COLS]; float dW[ROWS][COLS]; float dE[ROWS][COLS]; // Populate the input matrix printf("\n[srad] Populating the input matrix with random values"); fflush(stdout); for (i=0; i 0) { valN = values[i-1][j ] - current_value; } if (i < ROWS-1) { valS = values[i+1][j ] - current_value; } if (j > 0) { valW = values[i ][j-1] - current_value; } if (j < COLS-1) { valE = values[i ][j+1] - current_value; } // Compute the instantaneous coefficient of variation (qs) (equation 35) G2 = (valN*valN + valS*valS + valW*valW + valE*valE) / (current_value*current_value); L = (valN + valS + valW + valE ) / (current_value ); temp_a = (0.5*G2)-((1.0/16.0)*(L*L)); temp_b = 1+(0.25*L); qs = temp_a/(temp_b*temp_b); // Write the data dN[i][j] = valN; dS[i][j] = valS; dW[i][j] = valW; dE[i][j] = valE; // Set the diffusion coefficent (equation 33) float val = 1.0 / (1.0+( (qs-q0s)/(q0s*(1+q0s)) )); // Saturate the diffusion coefficent if (val < 0) { val = 0; } else if (val > 1) { val = 1; } coefficent[i][j] = val; } } // Iterate over the full image again and compute the final values for (i=0; i