This is the advanced version of the program, so help is just more questions.
Why do you store the blue/green/red values in temp, but store the upper saturated values in the original image array?
Why do you transfer from temp to image at the end?
This happens because the code is attempting to access an array element outside the bounds of the array. Remember that when an array is allocated a size of, say 5, the elements will run from 0 to 4. Height and width are array SIZES, so they each exceed the maximum allowable values by 1.
As for the for loop that the code is using to initialize the array, I ...