Skip to content

Commit

Permalink
Merge pull request #784 from iqraAmin/suite_dev
Browse files Browse the repository at this point in the history
Minor fix in seuratToGiottoV5
  • Loading branch information
jiajic authored Oct 30, 2023
2 parents a7a7a9a + 26a13ee commit 799c8c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
5 changes: 5 additions & 0 deletions R/images.R
Original file line number Diff line number Diff line change
Expand Up @@ -1545,9 +1545,14 @@ plot_giottoLargeImage = function(gobject = NULL,
if(isTRUE(asRGB) | terra::has.RGB(raster_object) | terra::nlyr(raster_object) >= 3) {
# Determine likely image bitdepth
if(is.null(max_intensity)) {

bitDepth = ceiling(log(x = giottoLargeImage@max_intensity, base = 2))
# Assign discovered bitdepth as max_intensity
max_intensity = 2^bitDepth-1

if(max_intensity == 0){
max_intensity = 1
}
}

terra::plotRGB(raster_object,
Expand Down
31 changes: 8 additions & 23 deletions R/interoperability.R
Original file line number Diff line number Diff line change
Expand Up @@ -1765,31 +1765,13 @@ seuratToGiottoV5 = function(sobject,
b <- as.matrix(sobject@images[[i]]@image[,,3])

# Convert channels to rasters
r <- raster::raster(r)
g <- raster::raster(g)
b <- raster::raster(b)

# Stack the channels and convert to brick
rgb_stack <- raster::stack(r, g, b)
rgb_raster <- raster::brick(rgb_stack)

#values rgb_raster
values_rgb_raster <- raster::values(rgb_raster)

# Rescale pixel values to the desired range (0-255) first
rescaled_values <- scales::rescale(values_rgb_raster, to = c(0, 255))

# Set the rescaled values in the raster object
rgb_raster <- raster::setValues(rgb_raster, values = rescaled_values)

# Convert to SpatRaster
rgb_raster <- as(rgb_raster, "SpatRaster")
r <- terra::rast(r)
g <- terra::rast(g)
b <- terra::rast(b)

# Create Giotto LargeImage
gImg <- createGiottoLargeImage(raster_object = rgb_raster)

# Plot the image
plot(gImg)
gImg <- createGiottoLargeImage(terra::rast(list(r, g, b)))

}
}
}
Expand Down Expand Up @@ -1820,6 +1802,9 @@ seuratToGiottoV5 = function(sobject,
gobject = addGiottoPolygons(gobject = gobject, gpolygons = polygon_list)
}

if(exists('gImg') == TRUE){
gobject = addGiottoLargeImage(gobject = gobject, largeImages = list(gImg))
}
return (gobject)
}

Expand Down

0 comments on commit 799c8c5

Please sign in to comment.