dahtah / imager

R package for image processing
GNU Lesser General Public License v3.0
187 stars 43 forks source link

"draw_circles" equivalent for line segments? #156

Closed mconsidine closed 3 years ago

mconsidine commented 3 years ago

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

ShotaOchi commented 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.

mconsidine commented 3 years ago

"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)