Testing
Most errors are a result of rounding too soon or incorrectly. To make this assignment a easier, double check the following:
- You understand the difference between
int()
andround()
- Make sure to truncate/round as late as possible. Doing these operations early on will make you lose precision
- Check that you are handling boundary/edge cases accurately
Rather than provide tests for A3, we will be giving you reference images that your outputs should match. There are ways to ensure your implementation is correct and that your outputs match the reference images (or at least are extremely close).
Checking Output and Reference are Equal
The first is actually provided for you. In many of the cells we have code that looks something like this:
print("Image is same as reference: ", np.array_equal(our_ref_image, your_output_image))
display(Image.fromarray(your_output_image))
If the output matches exactly with the reference image then this will output True. If the value for one channel for one pixel is off by even 1 then the output will be False.
Debugging
Unfortunately, your output may not be exactly the same as the reference, even if they look the same. Suppose the errors are almost imperceptible and can't be seen by visually inspecting your output image. In that case, we recommend you move on to the rest of the assignment and return later. For example, the reference images distortion-rotate-reference.png and distortion-rotate-reference-wrong.png look the same, but in the Comparing Images section of the NumPy_Tutorial notebook you see that they are actually different.
Don't spend a lot of time trying to debug your code if the output and reference images look the same but are not equal. If you find yourself spending hours trying to fix one pixel that is off just move on and come back!
Speaking of the Comparing Images section in the NumPy_Turorial notebook, please use what we've given you to help figure out what is wrong with your code. By examining the differences in your output with the reference, you can start to work backward and figure out where bugs in your code exist. In this section, we've provided code to:
- Check the max pixel difference across channels
- Check max and average pixel difference across the entire image
- Create an interactive plot that plots a color map of pixel differences but also allows you to hover over each pixel and see it’s value
A good idea would be to create a testing notebook with functions you write that take in reference and output images and run a series of comparisons. The ones listed in the NumPy_Tutorial notebook will help you get started, but please feel free to add other methods. Another helpful method would be to take the difference of two images and display them.