Downloading full resolution images using AllenSDK

Hello All,

This is my first post to the forum, so apologies if I am posting in the wrong category or with the wrong tags.

I am trying to download full-scale nissl stain images of the human brain atlas (Experiment Detail :: BrainSpan: Atlas of the Developing Human Brain)

I’ve downloaded the allenSDK, and I am using code that I found here: image_download

I’ve removed Pillow’s built in image size limits, and I am attempting to download the image using no downsampling. According to what I can tell from the documentation, either not specifying a downsample argument or setting the value to 0 should in theory provide me with the full res image.

However, this is not working, and is giving me an error. The code I am using is below, and the error messages are below that.

from allensdk.api.queries.image_download_api import ImageDownloadApi
from allensdk.api.queries.svg_api import SvgApi
from allensdk.config.manifest import Manifest

import matplotlib.pyplot as plt
from skimage.io import imread
import pandas as pd
from pathlib import Path

import logging
import os
from base64 import b64encode

from IPython.display import HTML, display
%matplotlib inline

from PIL import Image
Image.MAX_IMAGE_PIXELS = None

def verify_image(file_path, figsize=(18, 22)):
    image = imread(file_path)

    fig, ax = plt.subplots(figsize=figsize)
    ax.imshow(image)
    
    
def verify_svg(file_path, width_scale, height_scale):
    # we're using this function to display scaled svg in the rendered notebook.
    # we suggest that in your own work you use a tool such as inkscape or illustrator to view svg
    
    with open(file_path, 'rb') as svg_file:
        svg = svg_file.read()
    encoded_svg = b64encode(svg)
    decoded_svg = encoded_svg.decode('ascii')
    
    st = r'<img class="figure" src="data:image/svg+xml;base64,{}" width={}% height={}%></img>'.format(decoded_svg, width_scale, height_scale)
    display(HTML(st))

image_api = ImageDownloadApi()
svg_api = SvgApi()

output_dir = 'my/dir/'
atlas_image_id = 112282603
downsample = 0
annotation = False
file_path = Path(output_dir) / '112282603_nissl.jpg'
#I also tried using 112282603_nissl.tif to no avail

image_api.download_atlas_image(atlas_image_id, file_path, annotation=annotation, downsample=downsample)
verify_image(file_path)

Here are the errors I am receiving:
When using .tif extension

TiffFileError: not a TIFF file b'Cont'

When using .jpg extension

RuntimeError: Exception thrown in SimpleITK ImageFileReader_Execute: D:\a\SimpleITK\SimpleITK\Code\IO\src\sitkImageReaderBase.cxx:99:sitk::ERROR: Unable to determine ImageIO reader for "F:\Test\112282603_nissl.jpg"

Thank you for any advice!

Hi mpj, Thanks for your question and making us aware of this issue. We are not able to address this issue at this time due to lack of resources but plan to in the future.