EBImage Rendering of a DelayedArray Object
1
0
Entering edit mode
Dario Strbenac ★ 1.5k
@dario-strbenac-5916
Last seen 4 days ago
Australia

How can images of class DelayedArray be visualised? I imported them with loadImages function from cytomapper.

> dataset
CytoImageList containing 48 image(s)
names(48): 1_A3 1_A4 1_A5 1_A6 1_A7 1_A8 1_B1 1_B2 1_B3 ...
Each image contains 47 channel(s)
channelNames(47): 104Pd_104Pd.ome 113In_113In_HLA-ABC.ome 115In_115In_CD11c.ome ...
> display(dataset[[1]])
Error in validImage(x) : object must be an array
> class(dataset[[1]])
"DelayedArray"
> is(dataset[[1]], "array")
FALSE

It would seem intuitive for DelayedArray to have array as its parent class.

DelayedArray EBImage cytomapper • 495 views
ADD COMMENT
1
Entering edit mode

All of cytomappers functions support images stored as DelayedArray by simply calling as.array before e.g. visualization or quantification. In the past I have also used terra::aggregate to merge pixels/decrease resolution of images before converting them into an Image object for visualization.

ADD REPLY
1
Entering edit mode
@herve-pages-1542
Last seen 12 hours ago
Seattle, WA, United States

Extending an existing class means inheriting its internal representation. This does not work for the DelayedArray and array classes because they use completely different internal representations of the array data: the former uses an on-disk representation while the latter uses an in-memory representation.

Assuming DelayedArray objects are typically too big to fit in memory (otherwise one would just turn the object into an ordinary array with as.array() before calling display() on it), one way to make display() work on these objects is to implement a downsampling function. This is a function that would: (a) take a DelayedArray, (b) load a downsampled version of its data into memory, and (c) return that in an ordinary array. Such function would typically use a block-processing approach. Once such function is available, one could do:

a <- downsample(dataset[[1]])
display(a)

Note that, for additional convenience, the display() function could be turned into a generic. This would allow to define a method for DelayedArray objects that does something like callGeneric(downsample(x)).

These changes would need to happen in the EBImage package.

ADD COMMENT
0
Entering edit mode

Thanks, Hervé. Are you suggesting to make display a generic in BiocGenerics, and that EBImage defines method(s) for it, for regular array and Image objects, and that DelayedArray defines a method for its class(es)? Happy to support / coordinate such changes.

FWIW, we also have

$ EBImage:::plot.Image
function (x, ...) 
displayRaster(x, ...)
<bytecode: 0x11867fb30>
<environment: namespace:EBImage>

and displayRaster is one of the two methods implementing EBImage::display (the other one opens an interactive browser widget). I wonder whether a (better) alternative would be to use plot as the generic function, for DelayedArray as well as for regular array and Image objects... to unclutter terminology and not have needlessly ideosyncratic function names?

ADD REPLY

Login before adding your answer.

Traffic: 688 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6