PEP 8 specifies [four spaces per level of indentation](https://www.python.org/dev/peps/pep-0008/#indentation). Since whitespace matters in Python, this is a pretty strong convention. You should [`round()`](https://docs.python.org/3/library/functions.html#round) the results to the nearest integer rather than truncating them towards 0. Each of the three channels is treated identically and independently, so you shouldn't write the same code three times. def square_root_filter(input_image_file_name, output_image_file_name): image_data = skimage.io.imread(input_image_file_name) for row_data in image_data: for pixel in row_data: for channel in range(3): pixel[channel] = round(255 * math.sqrt(pixel[channel] / 255)) skimage.io.imsave(output_image_file_name, image_data) If you take advantage of the fact that `channels` is a NumPy array, you can vectorize the calculation. import numpy as np import skimage.io def square_root_filter(input_image_file_name, output_image_file_name): image_data = skimage.io.imread(input_image_file_name) for row_data in image_data: for pixel in row_data: pixel[:] = np.rint(255 * (pixel / 255) ** 0.5) skimage.io.imsave(output_image_file_name, image_data)