I would like to obtain the distance between a point and a selection of pixel on raster image. Here the process:
I read my JPEG image and extract colors I want:
img.raster<-stack(***)
names(img.raster) <- c('r','g','b')
img.a<-img.raster[[1]]
img.a[] =0
img.a[img.raster$r<70 & img.raster$g<70 & img.raster$b<255] <- 255
img.c<-img.raster[[1]]
img.c[] =0
img.c[img.raster$r>70 & img.raster$g>82 & img.raster$b>65] <- 255
img.b<-img.raster[[1]]
img.b[] =0
img.b[img.raster$r>65 & img.raster$r<160
& img.raster$g>70 & img.raster$g<255
& img.raster$b>0 & img.raster$b<65] <- 255
Then I recreate my final image and thus img.c is red, img.b is green and img.a is blue:
final_image = stack(img.c, img.b, img.a)
I am trying to calculate the distance between a point of coord (x,y) and all the pixels I extracted of the img.a. (in green in the following picture):
But if I calculate the distance between the point (xy) and img.a by using:
xy <- c(590,61)
d <- distanceFromPoints(img.a, xy)
I obtain the distance between all pixels (means the green and white).
Do you know how to select only the pixel I extracted on img.a ?