Metadata support#
[1]:
import os
import numpy as np
import cupy as cp
from matplotlib import pyplot as plt
Setting resource folder
[2]:
resources_dir = os.getenv("PYNVIMGCODEC_EXAMPLES_RESOURCES_DIR", "../assets/images/")
Import nvImageCodec module and create Decoder
[3]:
#os.environ['PYNVIMGCODEC_VERBOSITY'] = '5' uncomment for verbose log output
[4]:
from nvidia import nvimgcodec
decoder = nvimgcodec.Decoder()
Geo#
[11]:
img_full_path = os.path.abspath(os.path.join(resources_dir, "Alex_2016-01-14_1300Z_(Geotiff).tif"))
cs = nvimgcodec.CodeStream(img_full_path)
print("Number of images:", cs.num_images)
print("img.width", cs.width)
print("img.height", cs.height)
for code_stream_idx in range(0, cs.num_images):
scs = cs.getSubCodeStream(code_stream_idx)
metadata = decoder.getMetadata(scs)
for m in metadata:
print(m)
print(" "*5, m.buffer)
Number of images: 1
img.width 5000
img.height 6400
Metadata(kind=GEO format=JSON buffer_size=276)
b'{"MODEL_PIXEL_SCALE":[0.00259611,0.0022483,0],"MODEL_TIEPOINT":[0,0,0,-35.489,39.1935,0],"GT_MODEL_TYPE":2,"GT_RASTER_TYPE":1,"GEODETIC_CRS":4326,"GEODETIC_CITATION":"WGS 84","GEOG_ANGULAR_UNITS":9102,"ELLIPSOID_SEMI_MAJOR_AXIS":6.37814e+06,"ELLIPSOID_INV_FLATTENING":298.257}'
Decode image
[6]:
img = decoder.decode(cs)
print(img.__cuda_array_interface__)
plt.figure()
plt.imshow(img.cpu())
{'shape': (6400, 5000, 3), 'strides': None, 'typestr': '|u1', 'data': (64424509440, False), 'version': 3, 'stream': 1}
[6]:
<matplotlib.image.AxesImage at 0x7f35f0723bf0>

Aperio#
Aorta tissue, brightfield, JPEG 2000, YCbCr
[7]:
img_full_path = os.path.abspath(os.path.join(resources_dir, "JP2K-33003-1.svs"))
cs = nvimgcodec.CodeStream(img_full_path)
print("Number of images:", cs.num_images)
print("img.width", cs.width)
print("img.height", cs.height)
for code_stream_idx in range(0, cs.num_images):
scs = cs.getSubCodeStream(code_stream_idx)
metadata = decoder.getMetadata(scs)
for m in metadata:
print(m)
print(" "*5, m.buffer.decode('utf-8'))
Number of images: 6
img.width 15374
img.height 17497
Metadata(kind=MED_APERIO format=RAW buffer_size=530)
Aperio Image Library v10.0.50
16000x17597 [0,100 15374x17497] (256x256) J2K/YUV16 Q=70|AppMag = 40|StripeWidth = 1000|ScanScope ID = SS1283|Filename = 6797|Title = univ missouri 07.15.09|Date = 07/16/09|Time = 18:15:06|User = 93d70f65-3b32-4072-ba6a-bd6785a781be|MPP = 0.2498|Left = 39.010742|Top = 14.299895|LineCameraSkew = -0.003035|LineAreaXOffset = 0.000000|LineAreaYOffset = 0.000000|Focus Offset = -0.001000|DSR ID = homer|ImageID = 6797|OriginalWidth = 16000|Originalheight = 17597|Filtered = 3|ICC Profile = ScanScope v1
Metadata(kind=MED_APERIO format=RAW buffer_size=498)
Aperio Image Library v10.0.50
15374x17497 -> 674x768 - |AppMag = 40|StripeWidth = 1000|ScanScope ID = SS1283|Filename = 6797|Title = univ missouri 07.15.09|Date = 07/16/09|Time = 18:15:06|User = 93d70f65-3b32-4072-ba6a-bd6785a781be|MPP = 0.2498|Left = 39.010742|Top = 14.299895|LineCameraSkew = -0.003035|LineAreaXOffset = 0.000000|LineAreaYOffset = 0.000000|Focus Offset = -0.001000|DSR ID = homer|ImageID = 6797|OriginalWidth = 16000|Originalheight = 17597|Filtered = 3|ICC Profile = ScanScope v1
Metadata(kind=MED_APERIO format=RAW buffer_size=100)
Aperio Image Library v10.0.50
16000x17597 [0,100 15374x17497] (256x256) -> 3843x4374 J2K/YUV16 Q=70
Metadata(kind=MED_APERIO format=RAW buffer_size=100)
Aperio Image Library v10.0.50
16000x17597 [0,100 15374x17497] (256x256) -> 1921x2187 J2K/YUV16 Q=70
Metadata(kind=MED_APERIO format=RAW buffer_size=43)
Aperio Image Library v10.0.50
label 415x422
Metadata(kind=MED_APERIO format=RAW buffer_size=44)
Aperio Image Library v10.0.50
macro 1280x421
Decode all subimages
[8]:
for code_stream_idx in range(0, cs.num_images):
scs = cs.getSubCodeStream(code_stream_idx)
img = decoder.decode(scs)
plt.figure()
plt.imshow(img.cpu())






Philips#
Lymph node section, H&E stain, brightfield, BigTIFF, barcode attribute, from CAMELYON16 data set
[9]:
img_full_path = os.path.abspath(os.path.join(resources_dir, "Philips-1.tiff"))
cs = nvimgcodec.CodeStream(img_full_path)
print("Number of images:", cs.num_images)
print("img.width", cs.width)
print("img.height", cs.height)
for code_stream_idx in range(0, cs.num_images):
scs = cs.getSubCodeStream(code_stream_idx)
metadata = decoder.getMetadata(scs)
for m in metadata:
print(m)
print(" "*5, m.buffer.decode('utf-8'))
Number of images: 8
img.width 45056
img.height 35840
Metadata(kind=MED_PHILIPS format=XML buffer_size=9335)
<?xml version="1.0" encoding="UTF-8" ?>
<DataObject ObjectType="DPUfsImport">
<Attribute Name="DICOM_MANUFACTURER" Group="0x0008" Element="0x0070" PMSVR="IString">Hamamatsu</Attribute>
<Attribute Name="PIM_DP_SCANNED_IMAGES" Group="0x301D" Element="0x1003" PMSVR="IDataObjectArray">
<Array>
<DataObject ObjectType="DPScannedImage">
<Attribute Name="PIM_DP_IMAGE_TYPE" Group="0x301D" Element="0x1004" PMSVR="IString">WSI</Attribute>
<Attribute Name="UFS_IMAGE_PIXEL_TRANSFORMATION_METHOD" Group="0x301D" Element="0x2013" PMSVR="IString">0</Attribute>
<Attribute Name="DICOM_BITS_ALLOCATED" Group="0x0028" Element="0x0100" PMSVR="IUInt16">8</Attribute>
<Attribute Name="DICOM_BITS_STORED" Group="0x0028" Element="0x0101" PMSVR="IUInt16">8</Attribute>
<Attribute Name="DICOM_DERIVATION_DESCRIPTION" Group="0x0008" Element="0x2111" PMSVR="IString">tiff-useBigTIFF=1-useRgb=0-levels=10003,10002,10000,10001-processing=0-q80-sourceFilename="T14-03469_3311940 - 2015-12-09 17.29.29.ndpi"</Attribute>
<Attribute Name="DICOM_HIGH_BIT" Group="0x0028" Element="0x0102" PMSVR="IUInt16">7</Attribute>
<Attribute Name="DICOM_LOSSY_IMAGE_COMPRESSION" Group="0x0028" Element="0x2110" PMSVR="IString">01</Attribute>
<Attribute Name="DICOM_LOSSY_IMAGE_COMPRESSION_METHOD" Group="0x0028" Element="0x2114" PMSVR="IStringArray">"PHILIPS_TIFF_1_0"</Attribute>
<Attribute Name="DICOM_LOSSY_IMAGE_COMPRESSION_RATIO" Group="0x0028" Element="0x2112" PMSVR="IDoubleArray">"3"</Attribute>
<Attribute Name="DICOM_PHOTOMETRIC_INTERPRETATION" Group="0x0028" Element="0x0004" PMSVR="IString">RGB</Attribute>
<Attribute Name="DICOM_PIXEL_REPRESENTATION" Group="0x0028" Element="0x0103" PMSVR="IUInt16">0</Attribute>
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.000226891" "0.000226907"</Attribute>
<Attribute Name="DICOM_PLANAR_CONFIGURATION" Group="0x0028" Element="0x0006" PMSVR="IUInt16">0</Attribute>
<Attribute Name="DICOM_SAMPLES_PER_PIXEL" Group="0x0028" Element="0x0002" PMSVR="IUInt16">3</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_SEQUENCE" Group="0x1001" Element="0x8B01" PMSVR="IDataObjectArray">
<Array>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.000227273" "0.000227273"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">45056</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">0</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">35840</Attribute>
</DataObject>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.000454545" "0.000454545"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">22528</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">1</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">17920</Attribute>
</DataObject>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.000909091" "0.000909091"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">11264</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">2</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">9216</Attribute>
</DataObject>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.00181818" "0.00181818"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">5632</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">3</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">4608</Attribute>
</DataObject>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.00363636" "0.00363636"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">3072</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">4</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">2560</Attribute>
</DataObject>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.00727273" "0.00727273"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">1536</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">5</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">1536</Attribute>
</DataObject>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.0145455" "0.0145455"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">1024</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">6</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">1024</Attribute>
</DataObject>
<DataObject ObjectType="PixelDataRepresentation">
<Attribute Name="DICOM_PIXEL_SPACING" Group="0x0028" Element="0x0030" PMSVR="IDoubleArray">"0.0290909" "0.0290909"</Attribute>
<Attribute Name="PIIM_DP_PIXEL_DATA_REPRESENTATION_POSITION" Group="0x101D" Element="0x100B" PMSVR="IDoubleArray">"0" "0" "0"</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_COLUMNS" Group="0x2001" Element="0x115E" PMSVR="IUInt32">512</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_NUMBER" Group="0x1001" Element="0x8B02" PMSVR="IUInt16">7</Attribute>
<Attribute Name="PIIM_PIXEL_DATA_REPRESENTATION_ROWS" Group="0x2001" Element="0x115D" PMSVR="IUInt32">512</Attribute>
</DataObject>
</Array>
</Attribute>
<Attribute Name="PIM_DP_IMAGE_COLUMNS" Group="0x301D" Element="0x1007" PMSVR="IUInt32">45056</Attribute>
<Attribute Name="PIM_DP_IMAGE_ROWS" Group="0x301D" Element="0x1006" PMSVR="IUInt32">35840</Attribute>
<Attribute Name="PIM_DP_SOURCE_FILE" Group="0x301D" Element="0x1000" PMSVR="IString">%FILENAME%</Attribute>
</DataObject>
</Array>
</Attribute>
<Attribute Name="PIM_DP_UFS_BARCODE" Group="0x301D" Element="0x1002" PMSVR="IString">MzMxMTk0MA==</Attribute>
<Attribute Name="PIM_DP_UFS_INTERFACE_VERSION" Group="0x301D" Element="0x1001" PMSVR="IString">3.0</Attribute>
<Attribute Name="DICOM_SOFTWARE_VERSIONS" Group="0x0018" Element="0x1020" PMSVR="IStringArray">"4.0.3"</Attribute>
</DataObject>
Metadata(kind=MED_PHILIPS format=RAW buffer_size=25)
level=1 mag=22 quality=80
Metadata(kind=MED_PHILIPS format=RAW buffer_size=25)
level=2 mag=11 quality=80
Metadata(kind=MED_PHILIPS format=RAW buffer_size=26)
level=3 mag=5.5 quality=80
Metadata(kind=MED_PHILIPS format=RAW buffer_size=27)
level=4 mag=2.75 quality=80
Metadata(kind=MED_PHILIPS format=RAW buffer_size=28)
level=5 mag=1.375 quality=80
Metadata(kind=MED_PHILIPS format=RAW buffer_size=29)
level=6 mag=0.6875 quality=80
Metadata(kind=MED_PHILIPS format=RAW buffer_size=30)
level=7 mag=0.34375 quality=80
[10]:
for code_stream_idx in range(0, cs.num_images):
scs = cs.getSubCodeStream(code_stream_idx)
img = decoder.decode(scs)
plt.figure()
plt.imshow(img.cpu())







