Assuming the image is actually generated (that is, that index() is called), the reason for the 404 is that there is no route that points to the image, so Flask will tell you there is no mydomain.com/test.jpg. A static webserver like Apache or Nginx will by default map paths from a root to URLs, but an ordinary Flask/Werkzeug/WSGI setup will not do that.
Perhaps you want to create a resource that directly returns the image instead?
EDIT: Something similar should be able to serve images.
@app.route("/imgs/<path:path>")
def images(path):
generate_img(path)
fullpath = "./imgs/" + path
resp = flask.make_response(open(fullpath).read())
resp.content_type = "image/jpeg"
return resp
EDIT2: Of course, generate_img could probably be rewritten so it never write to disk but instead return image data directly.