crop.image: Crop an Image

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/crop.image.r

Description

Crop an image (matrix or array) with either pre determined bottom-left and top-right locations or interactively.

Usage

1
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

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

locator

Examples

 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)

imagefx documentation built on Feb. 14, 2020, 1:07 a.m.