I am using a combine command in EBImage in R. My images files are upto 100 images I have also set expression with following command
options(expressions=500000)
While I use combine function from EBImage package with following code
combine(Images_0)
I get a error command as Error: C stack usage 15925536 is too close to the limit
What am I doing wrong?
This assumes the Bioconductor package EBImage is available.
This many not exactly answer your question but I hope it is helpful. I am not certain of where the code is having problems but I find that combine()
can be very inefficient. There may be a do.call()
call buried in the call to combine, which can consume significant memory.
I find that abind()
of the abind
package is often a very effective solution. Without knowing more about the images you are trying to combine (it does help to provide minimal reproducible examples), let me suggest the following possibility.
# load library and read example color image
library(EBImage)
img <- readImage(system.file("images", "sample-color.png", package="EBImage"))
dim(img)
> [1] 768 512 3
# create a list of 48 images differing in lightness
images <- lapply(runif(48, 0.4, 1/0.4), function(x) img/x)
This is a reasonably sized list of color images. You can view the first image with print(img)
. The last command created 48 copies of the image that vary in lightness.
Now compare the time required to combine the images in that list with combine()
versus abind()
. Incidentally, abind()
has been slightly modified by EBImage
to handle dimnames
differently.
# First with combine()
system.time(x <- combine(images)) # rather fast AMD Ryzen 12-Core CPU
> user system elapsed
> 12.21 3.68 15.90
# Now with abind() where along = 4 adds a fourth dimension needed for the combination
system.time(y <- abind(images, along = 4)) # but much faster here
> user system elapsed
> 0.53 0.02 0.55
# The combined images are the same
identical(x, y)
> [1] TRUE
The timing would likely vary with machines and the need for disk access but it seems like a pretty big difference to me. With many images, abind
is really helpful. You can examine the combination with print(y, nx = 8, all = TRUE)
.
By the way, I would be curious to know if this fixed the "stack usage error."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.