I am about to write a java program which can smooth an image (2D Array) by a 3 by 3 mask and hesitate about which of the following strategies is right for application of the mask to the image:
1- Apply the mask to a portion of the image and immediately change the target pixel in the original image and move the mask to calculate the value of the next target pixel and so on.
2- Copy the original image into another backup image, then apply the mask to a portion of the original image and then change the target pixel in the copy image instead of original image.
In the second way, the original image would not change during the application of mask; only the new values are inserted into the backup image during smoothing. So the backup image will contain the smoothed image. Thanks.
Does not feel so good to answer my own question but in the spirit of helping others that have an image processing course and work with binary images, my experience might be helpful. After doing some trial-and-error experiments, I found that actually the second way is the right way and the first one is Wrong. Because changing the original values of a matrix while you are scanning it (at the same time) will lead to an inconsistency. I mean you will have a messed matrix at the end which won't maintain the original shape and instead of smoothing (removing noise pixels) it is just scrambling and ruining the original image. So, first I had to copy the original matrix and in each step of applying the mask, I just changed the target value in the copy matrix. Finally, the copied matrix would be your smoothed binary image.