threshold_color: Image to matrix - Single

Description Usage Arguments Value Author(s) Examples

View source: R/cnvIM.R

Description

Convert a single image into a matrix

Usage

1
2
3
4
threshold_color(filename, filetype = "jpeg", compress_method = "none",
  compress_rate = 1, target_width = 100, target_height = 100,
  threshold_value = 0.5, transparency_regulation = 0.5,
  channel = "rgb")

Arguments

filename

Name of the file to be load - ex: "Figure01.JPG".

filetype

Type of the file to be load. Compatible file types: ".JPGE", ".JPG" or ".PNG".

compress_method

For high resolution files, i.e. numbers of pixels in width and height, it is suggested to reduce the resolution to create a smaller matrix, it strongly reduce GPU usage and time necessary to run analyses. On the other hand, by reducing resolution, it will also reduce the accuracy of data description. The available methods for image reduction are: i) frame_fixed, which resamples images to a desired target width and height; ii) proportional, which resamples the image by a given ratio provided in the argument "proportion"; iii) width_fixed, which resamples images to a target width, and also reduces the image height by the same factor. For instance, if the original file had 1000 pixels in width, and the new width_was set to 100, height will be reduced by a factor of 0.1 (100/1000); and iv) height_fixed, analogous to width_fixed, but assumes height as reference.

compress_rate

Compress rate to by apply if compress_method=proportional. Note: it should be ser as number range from 0 to 1 .

target_width

Target width to be used if compress_method=frame_fixed or compress_method= width_fixed.

target_height

Target height to be used if compress_method=frame_fixed or compress_method= height_fixed.

threshold_value

For each pixel, the intensity of color channels (red, green and blue) are averaged and compared to a threshold_value (threshold). If the average intensity is less than the threshold_value (default is 0.5) the pixel will be set as black, otherwise it will be white. See channel argument.

transparency_regulation

For PNG images, the alpha channel is used to set transparent pixels, i.e. alpha channel values above transparency_regulation (a threshold) will set the pixel as transparent, default is 0.5. NOTE: In the data matrix the value 1 represents black pixels, 0 represents white pixels and NA represents transparent pixels.

channel

RGB channel to be considered in threshold. If channel=RGB (default), the intensity of red, green and blue is averaged and compared to threshold_value. If the average intensity is less than the threshold_value (default is 50 If only one channel is defined ("R" for red, "G" for green, and "B" for blue), the average intensity selected channel compared direct to the threshold_value value.

Value

A matrix of 0, 1 and NA representing white, black and transparent pixels, respectively.

Author(s)

Carlos Biagolini-Jr.

Examples

1
2
3
4
5
6
7
bush<-system.file("extdata/bush.JPG",package ="bwimage")
threshold_color(bush,"jpeg", "frame_fixed",target_width = 15,target_height=15)

# For your images, if the file is in the working directory type:
# threshold_color("FILE_NAME.EXTENSION", filetype ="FILE_EXTENSION")
# or, if the file is in the other directory:
# threshold_color("C:/PATH TO FILE FOLDER/YOUR_FILE_NAME.EXTENSION", "FILE_EXTENSION")

bwimage documentation built on April 23, 2020, 1:06 a.m.