What is PGM?
PGM is the greyscale member of the Netpbm family: a three-line header, then one brightness value per pixel with no compression. It is what image-processing courses, OCR pipelines and computer-vision tools pass around when they want a format with no decoder in the way.
What is ICNS?
ICNS is the macOS icon container - what sits inside an .app bundle. Since Lion it stores its images as ordinary PNGs at a handful of sizes, which is why reading one means picking the biggest member and writing one means rendering several.