readImage: Read and Resize an Image

View source: R/BioTrajectory.R View source: R/readImage.R

readImageR Documentation

Read and Resize an Image

Description

This function reads an image from a file path and resizes it to a specified number of rows. It supports several image formats, including JPG, JPEG, PNG, TIFF, and TIF. The function also converts the image into a suitable format for further processing.

Usage

readImage(path, resizeRows)

Arguments

path

The file path of the image to be read.

resizeRows

The desired number of rows (height) to resize the image. The aspect ratio of the image will be maintained during resizing.

Details

The function detects the image format based on the file extension. It currently supports the following formats: JPG, JPEG, PNG, TIFF, and TIF. If the image has more than 3 dimensions (such as an RGBA image with an alpha channel), the alpha channel is discarded. The image is resized only if its height exceeds the specified 'resizeRows'.

Value

A cimg object containing the resized image.

Examples

# Example usage
img_path <- system.file('extdata/data.tiff', package='BioTrajectory')
img <- readImage(img_path, resizeRows = 500)
plot(img)  # Visualizes the resized image


BioTrajectory documentation built on June 8, 2025, 11:54 a.m.