Is WordPress API visible from PHP file called in htaccess

The .htaccess is parsed before WordPress is loaded, so you don’t get access to WordPress data.

You can make the redirect in WordPress, in a plugin: Hook into 404_template and inspect $_SERVER['REQUEST_URI'] with parse_url(). You should be able to find the matching post for the image then.
You did not write how the permalinks for these posts are built, so we cannot offer a more specific solution.