Could be because JPEG compression loses information, so a write followed by a read only returns an approximation to the original. Try using a lossless format, such as BMP, instead of JPEG.
Also, do you need to write the image out to a file and read it back anyway? It's usually much more efficient simply to pass the image between functions or scripts in memory, using the name of the variable that refers to it.