img_center | R Documentation |
Center the input object within an output image of given dimensions, around a set of coordinates (by default the centroid of the object).
img_center(x, w, h, around = NULL, col = NULL)
x |
an image, of type |
w , h |
the width and height of the output image. |
around |
a vector with the x,y coordinate of the point around which to center; by default the centroid of the input image. |
col |
the colour to use for padding; by default the background colour from |
x <- img_read(system.file("extdata", "amphipoda/33463695.jpg",
package="morphr"), invert=TRUE)
img_show(x)
# center with all defaults
# = around the center of mass of grey levels
xc <- img_center(x, 350, 500) %>% img_show()
# check that the new centroid is around the middle of the image [175,250]
img_centroid(xc)
# center around the centroid of the binary image
# = does not take grey levels into account
xc <- img_center(x, 350, 500, around=img_centroid(x>0)) %>% img_show()
img_centroid(xc>0)
# the binary centroid is in the middle
img_centroid(xc)
# but the grey levels center of mass is elsewhere
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.