7373# '
7474# ' @export
7575setMethod(
76- f = ' [ ' ,
77- signature = c(' ImageArray' , " numeric" , " numeric" ),
76+ f = " [ " ,
77+ signature = c(" ImageArray" , " numeric" , " numeric" ),
7878 definition = function (x , i , j , ... , drop = FALSE ) {
7979 crop(x , ind = list (i , j ))
8080 }
@@ -85,10 +85,10 @@ setMethod(
8585# '
8686# ' @export
8787setMethod(
88- f = ' [[ ' ,
89- signature = c(' ImageArray' , " numeric" ),
88+ f = " [[ " ,
89+ signature = c(" ImageArray" , " numeric" ),
9090 definition = function (x , i ) {
91- return ( x @ levels [[i ]])
91+ x @ levels [[i ]]
9292 }
9393)
9494
@@ -97,28 +97,35 @@ setMethod(
9797# '
9898# ' @export
9999setMethod(
100- f = ' [[<-' ,
101- signature = c(' ImageArray' , " numeric" ),
100+ f = " [[<-" ,
101+ signature = c(" ImageArray" , " numeric" ),
102102 definition = function (x , i , ... , value ) {
103103 x @ levels [[i ]] <- value
104- return ( x )
104+ x
105105 }
106106)
107107
108108# ' @importFrom S4Vectors coolcat
109109# ' @noRd
110110setMethod(
111- f = ' show' ,
112- signature = c(' ImageArray' ),
111+ f = " show" ,
112+ signature = c(" ImageArray" ),
113113 definition = function (object ) {
114- cat(class(x = object ), " Object" ,
115- paste0(
116- " (" , paste(object @ meta [[" axes" ]], collapse = " ," ), " )"
117- ),
118- " \n " )
119- scales <- vapply(object @ levels ,
120- \(x ) sprintf(" (%s)" , paste0(dim(x ), collapse = " ," )),
121- character (1 ))
114+ cat(
115+ class(x = object ),
116+ " Object" ,
117+ paste0(
118+ " (" ,
119+ paste(object @ meta [[" axes" ]], collapse = " ," ),
120+ " )"
121+ ),
122+ " \n "
123+ )
124+ scales <- vapply(
125+ object @ levels ,
126+ \(x ) sprintf(" (%s)" , paste0(dim(x ), collapse = " ," )),
127+ character (1 )
128+ )
122129 S4Vectors :: coolcat(" Scales (%d): %s" , scales )
123130 }
124131)
@@ -142,7 +149,7 @@ setMethod("length", signature = "ImageArray", function(x) length(x@levels))
142149# '
143150# ' A function for creating objects of ImageArray class
144151# '
145- # ' @param meta the metadata of the ImageArray object.
152+ # ' @param meta the metadata of the ImageArray object.
146153# ' @param levels levels of the pyramid image, typically a vector of integers
147154# ' starting with 1
148155# '
@@ -197,7 +204,7 @@ createBFArray <- function(
197204# ' @param max.pixel.threshold the maximum width
198205# ' and height pixel dimension that the lowest level of the image pyramid
199206# ' should have, thus the image will be downscaled two folds until both width
200- # ' and height is below the threshold. Default is 700 pixels.
207+ # ' and height is below the threshold. Default is 700 pixels.
201208# ' If \code{n.levels} is provided, this parameter will be ignored.
202209# ' @param verbose verbose
203210# '
@@ -238,17 +245,19 @@ createMagickArray <- function(
238245 }
239246
240247 # create image levels
241- if (verbose )
248+ if (verbose ) {
242249 .img_create_msg(dim(image ), 1 )
250+ }
243251 image_data <- magick :: image_data(image , channels = " rgb" )
244252 storage.mode(image_data ) <- " integer"
245253 image_list <- list (DelayedArray :: DelayedArray(as.array(image_data )))
246254 if (n.levels > 1 ) {
247255 cur_image <- image
248256 for (i in 2 : n.levels ) {
249257 dim_image <- ceiling(dim_image / 2 )
250- if (verbose )
258+ if (verbose ) {
251259 .img_create_msg(dim_image , 1 )
260+ }
252261 cur_image <- magick :: image_resize(
253262 cur_image ,
254263 geometry = magick :: geometry_size_percent(50 ),
@@ -275,7 +284,7 @@ createMagickArray <- function(
275284# ' @param max.pixel.threshold the maximum width
276285# ' and height pixel dimension that the lowest level of the image pyramid
277286# ' should have, thus the image will be downscaled two folds until both width
278- # ' and height is below the threshold. Default is 700 pixels.
287+ # ' and height is below the threshold. Default is 700 pixels.
279288# ' If \code{n.levels} is provided, this parameter will be ignored.
280289# ' @param verbose verbose
281290# '
@@ -309,9 +318,10 @@ createEBImageArray <- function(
309318
310319 # create image levels
311320 meta <- list (axes = c(" x" , " y" , " c" ))
312- if (verbose )
321+ if (verbose ) {
313322 .img_create_msg(dim_image , 1 )
314- img_perm <- if (length(dim(image )) == 2 ) c(1 ,2 ) else c(1 , 2 , 3 )
323+ }
324+ img_perm <- if (length(dim(image )) == 2 ) c(1 , 2 ) else c(1 , 2 , 3 )
315325 meta [[" axes" ]] <- meta [[" axes" ]][img_perm ]
316326 img_perm <- stats :: setNames(img_perm , meta [[" axes" ]])
317327 img <- aperm(image , img_perm )
@@ -320,9 +330,9 @@ createEBImageArray <- function(
320330 cur_image <- image
321331 for (i in 2 : n.levels ) {
322332 dim_image <- ceiling(dim_image / 2 )
323- if (verbose )
333+ if (verbose ) {
324334 .img_create_msg(dim_image , i )
325- resize_factor <- dim_image
335+ }
326336 cur_image <- EBImage :: resize(
327337 cur_image ,
328338 w = dim_image [1 ],
@@ -346,13 +356,13 @@ createEBImageArray <- function(
346356# ' @param n.levels the number of levels of the pyramidal image,
347357# ' typical an integer starting from 1
348358# ' @param series the series IDs of the pyramidal image,
349- # ' typical an integer starting from 1.
359+ # ' typical an integer starting from 1.
350360# ' @param resolution the resolution IDs of the pyramidal image,
351- # ' typical an integer starting from 1.
361+ # ' typical an integer starting from 1.
352362# ' @param max.pixel.threshold the maximum width
353363# ' and height pixel dimension that the lowest level of the image pyramid
354364# ' should have, thus the image will be downscaled two folds until both width
355- # ' and height is below the threshold. Default is 700 pixels.
365+ # ' and height is below the threshold. Default is 700 pixels.
356366# ' If \code{n.levels} is provided, this parameter will be ignored.
357367# ' @param engine the package to use for each image layer: either
358368# ' \code{EBImage} or \code{magick-image}
@@ -447,15 +457,15 @@ createImageArray <- function(
447457# ' @param replace Should the existing file be
448458# ' removed or not
449459# ' @param n.levels the number of levels if the image supposed to be
450- # ' pyramidal.
460+ # ' pyramidal.
451461# ' @param chunkdim The dimensions of the chunks
452462# ' to use for writing the data to disk.
453463# ' @param level The compression level to use for
454464# ' writing the data to disk.
455465# ' @param engine the package to use for each image layer: either
456466# ' \code{EBImage} or \code{magick-image}
457467# ' @param verbose verbose
458- # ' @param ... additional parameters passed to
468+ # ' @param ... additional parameters passed to
459469# ' \link[ImageArray]{createImageArray}.
460470# '
461471# ' @importFrom HDF5Array writeHDF5Array
@@ -534,8 +544,9 @@ writeImageArray <- function(
534544 rhdf5 :: h5createFile(ondisk_path )
535545 }
536546 # TODO: is there a better way to check existing groups
537- if (! name %in% c(" " , " /" ))
547+ if (! name %in% c(" " , " /" )) {
538548 rhdf5 :: h5createGroup(ondisk_path , group = name )
549+ }
539550 },
540551 ZarrImageArray = {
541552 dir.zarr <- gsub(paste0(basename(ondisk_path ), " $" ), " " , ondisk_path )
@@ -548,7 +559,7 @@ writeImageArray <- function(
548559 ax <- axes(image_list )
549560 for (i in seq_len(length(image_list @ levels ))) {
550561 img <- image_list [[i ]]
551-
562+
552563 # write array
553564 switch (
554565 format ,
@@ -566,7 +577,7 @@ writeImageArray <- function(
566577 )
567578 },
568579 ZarrImageArray = {
569- chunk_dim <- stats :: setNames(dim(img ),ax )
580+ chunk_dim <- stats :: setNames(dim(img ), ax )
570581 chunk_dim [" x" ] <- min(chunk_dim [" x" ], 2000 )
571582 chunk_dim [" y" ] <- min(chunk_dim [" y" ], 2000 )
572583 image_list [[i ]] <-
@@ -583,15 +594,15 @@ writeImageArray <- function(
583594 }
584595
585596 # return
586- return ( image_list )
597+ image_list
587598}
588599
589600# ###
590601# Auxiliary ####
591602# ###
592603
593604# ' @noRd
594- .img_create_msg <- function (dim_img , i ){
605+ .img_create_msg <- function (dim_img , i ) {
595606 cat(paste0(
596607 " Creating level " ,
597608 i ,
0 commit comments