Description Usage Arguments Details Value Author(s) See Also Examples
Crop an image (matrix or array) with either pre determined bottom-left and top-right locations or interactively.
1 | crop.image(img, xleft, ybottom, xright, ytop, pick)
|
img |
matrix or array of image to crop |
xleft |
left extreme of crop area |
ybottom |
bottom extreme of crop area |
xright |
right extreme of crop area |
ytop |
top extreme of crop area |
pick |
logical value indicating whether crop region should be selected interactively (see details) |
if any of the xleft
, xright
, ybottom
, ytop
are missing, or if pick
is TRUE
, an interactive plot will aid in picking crop regions. The original image will be plotted and the user must first select the bottom left corner, then the top right corner of the desired crop area. A corresponding rectangle will be plotted indicating the current crop region. If the region is sufficient, the user should then click crop in the top right corner of the plotting area. If the region should be modified, the user should click repick.
Note that the xleft
, xright
, ybottom
, and ytop
locations correspond to R's reference frame for matrices, which can be confusing.
List of length two with
img.crop |
an object giving the cropped image with the same class (either matrix or array) of |
img.corners |
a vector with length 4 giving the the left, right, bottom, and top crop coordinates in the original image. |
Alex J.C. Witsil
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ############
### EG 1 ###
############
## example where you know where to crop the image
sakurajima.crop <- crop.image(sakurajima,xleft=146,ybottom=7,xright=203,ytop=256)
split.screen(c(1,2))
screen(1)
image2(sakurajima,asp=1,main='Original')
screen(2)
image2(sakurajima.crop[[1]],asp=1,main='Cropped')
## close screens
close.screen(all.screens=TRUE)
############
### EG 2 ###
############
## example where you choose where to crop using interactive plot
sakurajima.crop <- crop.image(sakurajima)
split.screen(c(1,2))
screen(1)
image2(sakurajima,asp=1,main='Original')
screen(2)
image2(sakurajima.crop[[1]],asp=1,main='Cropped')
print(sakurajima.crop[[2]])
## close screens
close.screen(all.screens=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.