Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image_connect component number collision #374

Open
aavogt opened this issue Jun 21, 2023 · 0 comments
Open

image_connect component number collision #374

aavogt opened this issue Jun 21, 2023 · 0 comments

Comments

@aavogt
Copy link

aavogt commented Jun 21, 2023

Below is self-contained example of image_connect assigning the same number to two pixels that are not connected. It only happens when there are too many components as determined by N.

library(magick)

N <- 21 # must be odd to get a grid instead of strips
w <- image_blank(N, N, color = "white")
b <- image_blank(1, 1, color="black")
get_row <- function(i) i %% N
get_col <- function(i) i %/% N
# NxN alternating 1x1 white and black squares
bw <- Reduce(function(w, i) {
                w2 <- image_composite(w, b, offset = paste0("+", get_row(i), "+", get_col(i)) )
                image_destroy(w)
                w2 },
        seq(1, N*N, by=2),
        w)
        
# bw %>% image_resize("400%") %>% image_browse

# FALSE for N >= 17 when there are collisions but
# TRUE for N <= 15 when there are no collisions
image_connect(bw) %>%
         image_raster %>%
         (function(x) all(table(x$col) == 1) )

image_connect could output a color image to encode components after component number 255. Or if that's not possible without changing the c++, I would like a warning that there are too many components for each to get a unique number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant