Learn R Programming

LS2Wstat (version 2.1-5)

cropimage: Crops a rectangular image to a specified (square) dimension

Description

If the input image is not of dimension \(2^n \times 2^n\), for some n, then the image is cropped to an optionally specified size.

Usage

cropimage(image, newsize = NULL, pos = "e")

Value

subim

A square image with dimension \(2^n \times 2^n\), where n is either newsize or the largest feasible dyadic power smaller than the original image dimensions.

Arguments

image

The image you wish to crop.

newsize

An optional dimension (smaller than the original image dimension), to which the image should be cropped.

pos

The position of the subimage to take when cropping an image. See the documentation for mix2images for more details.

Author

Matt Nunes

Details

As we often wish to work with images whose dimensions are some power of 2, this function will determine whether the image is of an appropriate size and if not it will crop the image so that it is. The optional pos argument specifies the position of the cropped subimage to be returned; for example pos="e" specifies the central region. See mix2images for more details on the positioning argument.

See Also

mix2images

Examples

Run this code
#
#Create an image with dimensions not a power of two
#
testimage <- matrix(rnorm(300^2),nrow=300,ncol=300)
#
#Crop the image
#
Newimage <- cropimage(testimage)
#
# Check new dimension size.
#
dim(Newimage)
#        

Run the code above in your browser using DataLab