downsize: Reducing the size of an RGB image

Description Usage Arguments Details Value Note Examples

View source: R/downsize.R

Description

This function reduces the size of each matrix of an RGB image (3-D array) by picking one component from every k1 components in each row and one component from every k2 components in each column of the input image, and use the selected elements to construct a reduced image, where k1 and k2 are specified by "RowSample" and "ColSample", respectively.

Usage

1
downsize(image, RowSample = 1, ColSample = 1)

Arguments

image

an input RGB image array

RowSample

a positive integer for the rows. Select one component from every RowSample components. For example, RowSample = 2 means you select the 1st, 3rd, ... element from each row of the original image to construct your new image.

ColSample

a positive integer for the columns. Select one component from every ColSample components. For example, ColSample = 2 means you select the 1st, 3rd, ... element from each column of the original image to construct your new image.

Details

This function can be used to reduce the size of an image by picking sample elements of the original image as the elements of the reduced image. For example, "RowSample = 2", and "ColSample = 2" reduce the original size of an image to a quarter.

Value

array of pixels of the reduced image.

Note

This function is different from another function in this package called "downsize_matrix( )". That function is used to reduce the size of matrices while this function, downsize( ), is used to reduce the size of 3-D arrays.

Examples

1
2
3
4
5
6
#read an RGB image
library(png)
image = readPNG(system.file("extdata", "image1.png",
                             package = "implant",
                             mustWork = TRUE))[ , ,c(1:3)]
downsize(image, RowSample = 2, ColSample = 2)

rwang14/implant documentation built on Sept. 6, 2020, 3:21 a.m.