Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions R/plotImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() |>
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
}
Expand Down
Loading