crop.image {imagefx} | R Documentation |
Crop an Image
Description
Crop an image (matrix or array) with either pre determined bottom-left and top-right locations or interactively.
Usage
crop.image(img, xleft, ybottom, xright, ytop, pick)
Arguments
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) |
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.
Value
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. |
Author(s)
Alex J.C. Witsil
See Also
Examples
############
### 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)