Extracting image data from pdz files

Good to know where we took the measurement…

The newest Bruker Tracer XRF spectrometers are equipped with a simple RGB camera that can be used to record the location of the spectral measurement. These RGB images are then encoded as jpg binary data that are stored within a single specific block (type 137) in the pdz file. If a pdz file actually contains one or more sets of image data you can use the extract_jpg() function to get them out.

from read_pdz import extract_jpg
pdz_file = '/home/frank/Work/DATA/read-pdz-demodata/00081-Precious Metals 2.pdz' # contains jpg image 
ims = extract_jpg(pdz_file, save_file=True)
Saving image file: '/home/frank/Work/DATA/read-pdz-demodata/00081-Precious Metals 2-0.jpg'

Let’s take a look at the image. Can anyone tell what we see here?

Code
import matplotlib.pyplot as plt
Code
fig, ax = plt.subplots()
ax.imshow(ims[0]);

Some pdz files contain multiple images. Let’s see how they look like.

pdz_file = '/home/frank/Work/DATA/read-pdz-demodata/with-three-images.pdz' 
ims = extract_jpg(pdz_file, save_file=True)
Saving image file: '/home/frank/Work/DATA/read-pdz-demodata/with-three-images-0.jpg'
Saving image file: '/home/frank/Work/DATA/read-pdz-demodata/with-three-images-1.jpg'
Saving image file: '/home/frank/Work/DATA/read-pdz-demodata/with-three-images-2.jpg'
Code
import matplotlib.pyplot as plt
Code
fig, axs = plt.subplots(ncols=3, figsize=[8, 3], squeeze=True)

for im, ax in zip(ims, axs): 
    ax.imshow(im)

FUNCTIONS


source

extract_jpg

 extract_jpg (pdz_file, BLOCKTYPE=137, save_file=False)

*Extract and save jpg images from pdz_file.

Returns a list of jpg images where ims = [ im0, im1, … ].*