My guess is that your RewriteRule is way too general, so rather than rewriting just that particular URL, you're actually rewriting every .jpg you use anywhere on your site!
As a result, in your particular problem at hand, you're rewriting and redirecting yourself in a circle, like so:
1) You navigate to http://mysite.com/image/mycode.jpg
2) The rewrite rule matches and calls for the script at /image/mycode.php
3) That script returns a redirect to http://mysite.com/image/15.jpg
4) The browser requests that URL
5) The rewrite rule matches and calls for the file at /image/15.php
6) Apache can't find a file there and returns a 404 File Not Found message to the browser
To get around this, make your RewriteRule more specific:
RewriteRule ^(.*mycode)\.jpg $1.php
Now, it'll only try to rewrite URLs with mycode.jpg, so 5 and 6 above will never happen, and you should get the result you're after.