Closed mconsidine closed 3 years ago
It's convenient to use magick package to do it. We can convert cimg object into magick-image object and vice versa.
"implot" seems to accomplish what I was looking for, though it requires Cairo. And the axis scaling comes out differently than with the original example (when used with a real example, at least in my test).
df <- expand.grid(x=1:10,y=1:10) %>% dplyr::mutate(value=0.5) testim <- as.cimg(df,dims=c(10,10,1,1)) plot(testim) lineseg <- matrix(c(5,5,6,6,6,8,9,10),nrow=4,byrow=TRUE) colnames(lineseg)<-c('x','y') lines(lineseg,col="red") testim2 <- implot(testim,lines(lineseg,col="red",lwd=1)) plot(testim2)
I think I'm overlooking something and I hope I can get a suggestion to set me straight. Here's a reproducible example:
df <- expand.grid(x=1:10,y=1:10) %>% dplyr::mutate(value=0.5) testim <- as.cimg(df,dims=c(10,10,1,1)) plot(testim) lineseg <- matrix(c(5,5,6,6,6,8,9,10),nrow=4,byrow=TRUE) colnames(lineseg)<-c('x','y') lines(lineseg,col="red")
What I want to do is change in the image itself the values of the coordinates represented by "lineseg". The "lines" function correctly draws the red lines over the plot, but I want to add them to the image.
I have been goofing around with pixsets all morning and - as usual - must be missing something very basic, because I can't this to work. Ideally, I want to create "testim2" that has the original image with the additional one overlaid.
Thanks, Matt