dimanche 19 avril 2015

Draw a complete circle with specific radius and crop borders in R

I'm loading bitmap images into R with dimensions that are roughly 17,000 X 17,000 pixels. I'd like to find a way to draw a circle with a radius (in pixels) of my choosing around the center of the picture and convert all pixels outside of the circle into NA's. For example, if the radius desired was 500 pixels, all pixels within that distance (500) from the centroid would be kept as is. Any pixel farther than that distance (>= 501) from the centroid would be converted to an NA.


The bitmap images are made up entirely of 1's and 0's so here's a smaller example of what these images look like.



img=matrix(sample(c(1,0),1000000,replace=TRUE),ncol=1000,nrow=1000)
image(0:1000,0:1000,img)

Aucun commentaire:

Enregistrer un commentaire