Skip to content

Accessing images

Joe Futrelle edited this page Nov 4, 2016 · 3 revisions

Retrieving images

IFCB produces two-dimensional 8-bit grayscale images. These can be accessed using the images property of a sample bin.

The images property is dict-like, where keys are target numbers and values are numpy arrays. This example computes the average grayscale value for each image in a sample bin:

for target_number in sample_bin.images:
    average_value = np.mean(sample_bin.images[target_number])
    ...

Optimization

If you only want to access one image from a sample bin, it is possible to do this efficiently using the sample bin's as_single method. This method skips computationally-expensive parsing operations to allow rapid access to a single image and associated ADC data, but precludes access to other images and their ADC data. This example retrieves ROI number 128 from a sample bin:

with sample_bin.as_single(128) as single_bin:
    image = single_bin.images[128]

If you attempt to access other images or ADC data on a sample bin returned by as_single, a KeyError exception will usually be raised. Do not use as_single if you want to access more than one image.

Clone this wiki locally