Respuesta :

Code for calculating the median, geometric mean, arithmetic mean, adaptive local noise reduction, and adaptive median filters. Your software receives a 2d matrix as input:

// Median

function median(matrix) {

 // sort array

 const sorted = matrix.sort((a, b) => a - b);

 const mid = Math.floor(sorted.length / 2);

 const isEven = sorted.length % 2 === 0;

 if (isEven) {

   return (sorted[mid - 1] + sorted[mid]) / 2;

 }

 return sorted[mid];

}

// Arithmetic Mean

function arithmeticMean(matrix) {

 return matrix.reduce((a, b) => a + b, 0) / matrix.length;

}

// Geometric Mean

function geometricMean(matrix) {

 return Math.pow(

   matrix.reduce((a, b) => a * b, 1),

   1 / matrix.length

 );

}

// Adaptive Local Noise Reduction

function adaptiveLocalNoiseReduction(matrix) {

 const result = [];

 const windowSize = 3;

 for (let i = 0; i < matrix.length; i++) {

   for (let j = 0; j < matrix[i].length; j++) {

     const nums = [];

     for (let x = i - windowSize; x <= i + windowSize; x++) {

       for (let y = j - windowSize; y <= j + windowSize; y++) {

         const row = matrix[x] ? matrix[x][y] : 0;

         if (row) {

           nums.push(row);

         }

       }

     }

     result.push(median(nums));

   }

 }

 return result;

}

// Adaptive Median Filter

function adaptiveMedianFilter(matrix) {

 const result = [];

 const windowSize = 3;

 for (let i = 0; i < matrix.length; i++) {

   for (let j = 0; j < matrix[i].length; j++) {

     const nums = [];

     for (let x = i - windowSize; x <= i + windowSize; x++) {

       for (let y = j - windowSize; y <= j + windowSize; y++) {

         const row = matrix[x] ? matrix[x][y] : 0;

         if (row) {

           nums.push(row);

         }

       }

     }

     const medianValue = median(nums);

     const medianDiff = nums.map((x) => Math.abs(x - medianValue));

     const minDiff = Math.min(...medianDiff);

     const minIndex = medianDiff.indexOf(minDiff);

     result.push(nums[minIndex]);

   }

 }

 return result;

}

What is code?
Code is a set of instructions, written in a programming language, that tells a computer what to do. Code can be written to create software applications, websites, and mobile apps, among other things. Code is written using specific programming languages, such as C++, Java, Python, and HTML. Programmers use code to define how a program should work and to give the computer a set of instructions to execute. Code is the cornerstone of the digital world, and it is the basis for all computer-related tasks. Without code, computers would be unable to perform any task.

To learn more about code

https://brainly.com/question/23275071

#SPJ4