NRRD or SEG.NRRD to PNG

So I have a request from somene to export his DICOM and NRRD files 5 of them into a set of PNG images.

Images are to be numbered and saved without losing any info, in other words either a lossless compression format or no compression at all.

What can I do now?

I have no idea why exactly he needs them saved as PNGs

You can load the DICOM files and export the segmentation to labelmap volumes (using the GUI), then save them into a series of png as shown at the end of this script (starting from line outputLabelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass...).

dear lassoan, first of all I want to thank you for all of your help. May God bless you sir.

Concerning this script, IF I understood you correctly, I just have to make a py file that contains this and then save it by running this script?

outputLabelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(seg, outputLabelmapVolumeNode, referenceVolumeNode)
outputLabelmapVolumeArray = (slicer.util.arrayFromVolume(outputLabelmapVolumeNode) * outputVolumeLabelValue).astype('int8')

# Write labelmap volume to series of TIFF files
pip_install("imageio")
import imageio
for i in range(len(outputLabelmapVolumeArray)):
    imageio.imwrite(f'{outputDir}/image_{i:03}.tiff', outputLabelmapVolumeArray[i])

is this loseless? Will I lose some of the information?

By saving into a series of 2D images, you lose 3D image geometry information (origin, spacing, and axis directions), so you cannot properly process the image in physical space. You also make your life harder and slow things down by storing your volume in hundreds of files instead of a single 3D image file.

I understand that orientation will be lost along with spacing and axis and direction.

But someone wants to print an entire set of images for some reason and also to share them only whatever and whichever they pick.

It is something they discovered on the scan and made high resolution scan of it.

Now they don’t want to always come and take screenshots or whatever but would simply like to have the entire thing in a set of pngs and just pick whichever png they want and send it to their colleague.

that is what they told me when they said they want it as pngs sequence.

so that is why my question is narrowly about the image color and resolution loss. If some information would be lost and if the lines I selected out are the correct ones. I can just enclose them in a notepadfile.py and then just run it?