PDF generally uses two types of means to store images, One is to take the raw image and embed it. Those are usually jpg and tend to use one type of compression. there are several methods like inline and indirect but the point is they are "as inserted".
Thus they will not change compression or quality, unless extracted, recompressed and re-inserted. A Question that many people ask is why cant I compress PDF images in place !, possible but tricky.
The other way is the RGB or GREY or MONO components are inserted as bitmaps (of one type or another) and for PNG (or those with Alpha Transparency) a second image is added as a SoftMask. Thus now 2 images per insertion. These are even harder to handle.
So easy FOSS solutions are hard to come by.
PDFImages -list will give you clues as to some structures and extract what it can (not all)
e.g.
--0000.ppm: page=1 width=1800 height=682 hdpi=599.67 vdpi=599.12 colorspace=DeviceRGB bpc=8
--0001.ppm: page=3 width=1834 height=665 hdpi=345.93 vdpi=345.75 colorspace=DeviceRGB bpc=8
so what images are those ? the first is 22 colours of near black and near white thus greyscale but almost monochrome in nature, could be converted externally to 600 dpi black and white
!
The second is a screenshot from Amazon showing an I Phone so a high proportion of Orange
and Black
with some Red
and Blue
too, thus that can be converted into a JPEG or PNG (without alpha), at 346 dpi.xxx
as whichever you wish !

And so on. In this case the majority are better candidates for lossless PNG, than that second one which alone would best be output as if it were a JPEG.
Basically reversing PDF raw image inputs is not simple for deciding what to output.
Untested
but try $ pypdfium2 extract-images --help to see its built in options are (I understand from docs --render should help)