On main page, in each post, display image depending on post category

You probably don’t actually want to edit index.php. It is the most generic fallback template when WP doesn’t have anything else to go on. Most themes have a front-page.php or blog.php which is where you’ll find the loop you are trying to modify. Those files may in turn point to a template part so it really depends on your theme as to which file you need to adjust.

You can identify the “parent template” (the main file serving the current page, such as front-page.php) using code here – How do you find out which template page is serving the current page? – but again that only tells you the overall template file being used. If a template part is responsible for the part of the code you’re trying to modify, you’ll have to follow the breadcrumb trail to figure out which file is the one you’re looking for.