Open dgemara opened 5 years ago
If you wish to replace all pixels with an exact colour value, try this:
##all pixels with colour c1 are given colour c2
replaceColour <- function(im,c1,c2)
{
#Split into channels
l <- imsplit(im,"c")
#Find pixels that match over all channels
sel <- map2_il(c1,l,function(a,b) b==a) %>% parall
#Replace, reconstruct
map2_il(c2,l,function(a,b) { b[sel]=a; b }) %>% imappend("c")
}
replaceColour(boats,color.at(boats,55,12),c(0,0,0)) %>% color.at(55,12)
If you need to select all pixels that are say, approximately red, have a look at
https://dahtah.github.io/imager/gimptools.html#selection-by-similarity
For example, replacing all pinks with blacks. I was thinking of editing the actual dataframe (ie as.data.frame(im,wide="c")) and changing each instance of a pixel with the color I want. I know there are variations of this in the vignette, such as color.at <- and R(x) <- value, but I can't seem to see a specific one for changing a specific color.