The ImageDownloadApi class in the AllenSDK provides a Python interface for accessing image data produced by the Allen Institute for Brain Science.

Contents:

Reference Documentation:

In [1]:
from allensdk.config.manifest import Manifest

import matplotlib.pyplot as plt
import pandas as pd

import logging
import os

%matplotlib inline

We will want to look at the images we download in this notebook. Here is a simple function which does that:

In [2]:
def verify_image(file_path, figsize=(18, 22)):

fig, ax = plt.subplots(figsize=figsize)
ax.imshow(image)

In [3]:

In this example, we will download a single section image from Mouse Brain Atlas experiment 71210895.

For now, we'll assume that we already know the id (unique integer identifier) of the image that we wish to download. In a later section, we'll use our ImageDownloadApi instance to find the ids of all the images from a particular experiment.

In [4]:
section_image_id = 70945123
file_path = '70945123.jpg'

The raw images can be quite large, so we will download downsampled versions. The downsample keyword argument reduces the size of the obtained image by a factor of $2^{\text{downsample}}$ along each axis.

In [5]:
downsample = 3

Now we download the image using our api object and view it in the notebook.

In [6]:

verify_image(file_path)

In this example, we will download a single section image from Mouse Brain Connectivity experiment 297225422.

In [7]:
section_image_id = 297225716
file_path = '297225716_connectivity.jpg'
downsample = 3

In order to clearly distinguish projection signal from background structure, it helps to window and rescale each channel. We have precomputed channelwise windows for each section data set in the connectivity atlas. You can obtain these window parameters using the ImageDownloadApi

In [8]:
ranges = image_api.get_section_image_ranges([section_image_id])[0]

Then simply pass them in via the range keyword argument.

In [9]: