Skip to content

Commit e622a46

Browse files
authored
Merge pull request #215 from drieslab/dev2
v0.3.3
2 parents 848d41d + 0bbea28 commit e622a46

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: GiottoClass
22
Title: Giotto Suite object definitions and framework
3-
Version: 0.3.2
3+
Version: 0.3.3
44
Authors@R: c(
55
person("Ruben", "Dries", email = "rubendries@gmail.com",
66
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7650-7754")),

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
# GiottoClass 0.3.3
3+
4+
## bug fixes
5+
- fix flipping issue with `giottoAffineImage` for certain affine transforms
6+
7+
## enhancements
8+
- `missing` method for `affine()` instantiates an `affine2d` object
9+
210
# GiottoClass 0.3.2 (2024/07/26)
311

412
## breaking changes

R/giotto_structures.R

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@
185185
.magick_image_corners <- function(x) {
186186
checkmate::assert_class(x, "magick-image")
187187
im_info <- magick::image_info(x)
188+
189+
# generate spatLocsObj as a set of control points for magick distort. #
190+
# ------------------------------------------------------------------- #
191+
# - magick uses 0.5 to refer to the center of pixels
192+
# - 3 points are needed for an affine distort
193+
# pt1: bottom left
194+
# pt2: top left
195+
# pt3: bottom right
188196
spatLocsObj(
189197
name = "mg_ctrl_coords",
190198
coordinates = data.table::data.table(

R/methods-affine.R

+20-4
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,15 @@ setMethod(
150150
}
151151
)
152152

153+
# * missing, missing ####
154+
#' @rdname affine
155+
#' @export
156+
setMethod("affine", signature(x = "missing", y = "missing"), function(x) {
157+
new("affine2d", affine = diag(c(1, 1)))
158+
})
153159

154-
# * ANY ####
160+
161+
# * ANY, missing ####
155162
#' @rdname affine
156163
#' @export
157164
setMethod("affine", signature(x = "ANY", y = "missing"), function(x) {
@@ -337,12 +344,21 @@ setMethod("affine", signature(x = "affine2d", y = "matrix"), function(
337344
.gaffine_realize_magick <- function(x, size = 5e5, ...) {
338345
mg <- .spatraster_sample_values(x, output = "magick", size = size, ...)
339346
aff <- x@affine
347+
348+
# create a dummy spatLocsObj to act as control points
349+
# pt1: bottom left
350+
# pt2: top left
351+
# pt3: bottom right
340352
dummy_sl <- .magick_image_corners(mg)
341-
aff_dummy_sl <- affine(dummy_sl, .aff_linear_2d(aff)) %>%
353+
aff_dummy_sl <- dummy_sl %>%
354+
affine(.aff_linear_2d(aff)) %>%
342355
flip() %>%
343-
rescale(fx = 1 / aff$scale[["x"]], fy = 1 / aff$scale[["y"]])
344-
# no rescaling should be performed at this step. Otherwise magick
356+
rescale(fx = 1 / abs(aff$scale[["x"]]), #*see below
357+
fy = 1 / abs(aff$scale[["y"]]))
358+
# *no scaling should be performed at this step. Otherwise magick
345359
# will generate a differently sized image during distortion
360+
# To prevent the scaling change, we use the decomposed scale values.
361+
# However, flips ARE desired, so we make sure the use the abs() values.
346362

347363
.sl_to_mat <- function(x) {
348364
x[][, c("sdimx", "sdimy")] %>% t()

man/affine.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)