what formats can I extract images in?

26 views
Skip to first unread message

mattob...@gmail.com

unread,
Mar 8, 2018, 8:09:31 PM3/8/18
to bisque bioimage
Hi,

I can extract a slice from a stack of dicoms as such:

image = session.load(img_to_load)
image = image.pixels().slice(z=0, t=10).format('tiff').fetch(img_to_write)

Where can I read documentation about what formats I can export out? What kind of image compression and other options are available? Can I export out raw pixel values as a numpy array?

Thanks
Matt

Dmitry Fedorov

unread,
Mar 9, 2018, 4:21:18 PM3/9/18
to bisque-...@googlegroups.com
Hi Matt,

Where can I read documentation about what formats I can export out?

You can query your running system for currently supported formats, system may have plugins with more supported formats, each format has a full description of what operations are supported:

You can also see the list in the UI, upload -> formats

Most system will have at list our own libbioimage which supports:
 
What kind of image compression and other options are available? Can I export out raw pixel values as a numpy array?

Once you download a tiff image, be default it is exported with a lossless LZW compression which once loaded with sckit io will give you a numpyarray. Image service does not export a numpy memory footprint directly. You can use a RAW uncompressed stream of bytes if you want, that way we typically load data into matlab array on the fly:

One could request to get a pyramidal tiled tiff with LZMA compression using :
https://HOST/image_service/UUID?slice=,,10,&format=tiff,compression,lzma,tiles,512,pyramid,subdirs

Those comma separated options are passed directly to libbioimage, there are several and they depend on the format being exported. You can see the options available running imgcnv:

-options              - specify encoder specific options, ex: -options "fps 15 bitrate 1000"

Video files AVI, SWF, MPEG, etc. encoder options:
  fps N - specify Frames per Second, where N is a float number, if empty or 0 uses default, ex: -options "fps 29.9"
  bitrate N - specify bitrate in Mb, where N is an integer number, if empty or 0 uses default, ex: -options "bitrate 10000000"

JPEG encoder options:
  quality N - specify encoding quality 0-100, where 100 is best, ex: -options "quality 90"
  progressive no - disables progressive JPEG encoding
  progressive yes - enables progressive JPEG encoding (default)

TIFF encoder options:
  compression N - where N can be: none, packbits, lzw, fax, jpeg, zip, lzma, jxr. ex: -options "compression lzw"
  quality N - specify encoding quality 0-100, where 100 is best, ex: -options "quality 90"
  tiles N - write tiled TIFF where N defined tile size, ex: tiles -options "512"
  pyramid N - writes TIFF pyramid where N is a storage type: subdirs, topdirs, ex: -options "compression lzw tiles 512 pyramid subdirs"

JPEG-2000 encoder options:
  tiles N - write tiled TIFF where N defined tile size, ex: tiles -options "2048"
  quality N - specify encoding quality 0-100, where 100 is lossless, ex: -options "quality 90"
JPEG-XR encoder options:
  quality N - specify encoding quality 0-100, where 100 is lossless, ex: -options "quality 90"
WebP encoder options:
  quality N - specify encoding quality 0-100, where 100 is lossless, ex: -options "quality 90"

 -d
Message has been deleted

Matt O'Brien

unread,
Mar 9, 2018, 8:00:41 PM3/9/18
to bisque bioimage
Thanks so much for the guidance -- this is exactly what I was looking for with respect to image formats. Great to know there are the options I was looking for.

Dmitry Fedorov

unread,
Mar 9, 2018, 8:25:22 PM3/9/18
to bisque-...@googlegroups.com
Hi Matt,

This works fine to extract a particular no-zero indexed slice: 

image = image.pixels().slice(z=0, t=10).format('tiff').fetch(img_to_write)

...but any time the value of t == 0, I get back the full image. A slice is not returned, rather, a full 3D stack of images.

Using .shape in numpy shows they are 3D. It's also clear by the file sizes (the first and last were slice=,,,0):

 

Any ideas on how to extract the 0th image?


The reason for this is a past relic. Slice operands go [1..N] and 0 or empty means the whole range, this is why you skip x or y and get the whole plane. It was done to be similar to matlab for developers who would not be comfortable with 0 starts. There's an old documentation for the image service here:

But teh best way to see what your current system can support is via the operations:
    /image_service/operations

<tag name="slice" value="slice: returns an image of requested slices, arg = x1-x2,y1-y2,z|z1-z2,t|t1-t2 in ranges [1..N] or arg = z:V|v1-v2,fov:V,... in ranges [0..N-1]"/>

You may notice that there's a new form to define slices that gives more dimensions than 5-D of the old-style and it also starts with 0. The python api allows providing all kinds of requests via strings so to allow you to use enhanced operations:
    image.pixels().command('slice', 'z:0').fetch(filename)

-d

Matt O'Brien

unread,
Apr 16, 2018, 3:54:21 PM4/16/18
to bisque bioimage
Thanks for your help with image formats.

So, if I were to require BisQue to export slice of a dicom, which should be a raw greyscale image, what would be the appropriate imgcnv options?

As in, 

Dmitry Fedorov

unread,
Apr 17, 2018, 11:43:51 AM4/17/18
to bisque-...@googlegroups.com
Hi Matt,
 
So, if I were to require BisQue to export slice of a dicom, which should be a raw greyscale image, what would be the appropriate imgcnv options?

As in, 


The requests form a processing pipeline, in this case, extracting z slice == 10 and exporting the result as a RAW format. Thus it does not guarantee the grayscale nature. If your images are one channel that is what you will get but if images happen to come with more channels then you will get more channels. If you just want a greyscale output you might want to add a channel extraction:

    https://HOST/image_service/UUID?slice=,,10,&remap=1&format=raw

in this case extracting the first channel fro the image.

Although these might get a bit more difficult if you are dealing with RGB, RGBA or false color images, for which you might want to use "fuse" operations, for example, fuse into a greyscale image:

    https://HOST/image_service/UUID?slice=,,10,&fuse=grey&format=raw

Just a note that we're talking about image service requests, not the bio-image convert command line utility, although many commands are similar they are not the same!

-dmitry


Reply all
Reply to author
Forward
0 new messages