Salt & pepper noise is implemented using a random number generator to randomly add black or white pixels on the image. User can provide a noise ratio to indicate how frequent the black or white pixel should appear. The noise ratio acts as a threshold to the values generated by the random number generator: the algorithm traverses every pixel in the image and generates a random number every time. Ifthe generated number is above the noise ratio, we do nothing; otherwise we compare this random numberwithnoiseratio2: if it is below half of the noise ratio, we replace the pixel with a black colour; otherwise we replace the pixel with a white colour.
See the project report for more details.