diff --git a/R/plotImage.R b/R/plotImage.R index ce950fd..af48765 100644 --- a/R/plotImage.R +++ b/R/plotImage.R @@ -101,8 +101,8 @@ NULL cl <- matrix(cl, ncol=2) } colors_rgb <- col2rgb(c) - normed_a <- (t(linear_a) - cl[, 1]) / (cl[, 2] - cl[, 1]) - flat_img <- tcrossprod(colors_rgb, normed_a) / d + normed_a <- (linear_a - cl[, 1]) / (cl[, 2] - cl[, 1]) + flat_img <- (colors_rgb %*% normed_a) / d flat_img |> t() |> farver::encode_colour() |> @@ -142,7 +142,6 @@ NULL #' @importFrom SpatialData channels #' @noRd .ch_idx <- \(x, ch) { - if (.is_rgb(x)) return(seq_len(3)) if (is.null(ch)) return(1) lbs <- channels(x) if (all(ch %in% lbs)) { @@ -205,9 +204,14 @@ setMethod("plotImage", "SpatialData", \(x, i=1, j=1, k=NULL, ch=NULL, c=NULL, cl j <- CTname(y)[j] y <- transform(y, j) wh <- .get_wh(y) + if (.is_rgb(y)) { + # RGB: we plot everything by default and we don't normalize + ch <- ch %||% channels(y) + cl <- cl %||% c(0, 1/3) + } df <- .df_i(y, k, ch, c, cl) - pal <- if (is.null(c)) .DEFAULT_COLORS else c - if (dim(y)[1] > 1) { + pal <- c %||% .DEFAULT_COLORS + if (dim(y)[1] > 1 && !.is_rgb(y)) { nms <- unlist(channels(y))[idx <- .ch_idx(y, ch)] pal <- pal[seq_along(idx)]; names(pal) <- nms }