Before installing Rvision
, you will need to install the latest version of the devtools
package in R
.You can install devtools
as follows:
install.package("devtools")
You can install Rvision
as follows:
devtools::install_github("swarm-lab/Rvision")
Rvision
depends on ROpenCVLite
to access OpenCV
’s functionalities. If not already installed, ROpenCVLite
will be installed first by the above command line. This may take some time as it will download, compile and install OpenCV
for you (compilation time will depend on your computer). I suggest going out for a cup of tea or coffee while ROpenCVLite
is installing ;-)
library(Rvision)
# Locate sample file
samplePath <- system.file("sample_img", "bunny.png", package = "Rvision")
# Read image file
img1 <- image(samplePath)
img1
## C++ object <0x7ffe3de9bd50> of class 'Image' <0x7ffe3dcabb30>
plot(img1)
dim(img1)
## [1] 720 1280 4
nrow(img1)
## [1] 720
ncol(img1)
## [1] 1280
nchan(img1)
## [1] 4
bitdepth(img1)
## [1] "8U"
colorspace(img1)
## [1] "BGRA"
outfile = tempfile(fileext = ".png")
write.Image(img1, file = outfile)
## [1] TRUE
file.exists(outfile)
## [1] TRUE
img2 <- changeColorSpace(img1, "GRAY")
plot(img2)
img3 <- img2 > 128 # Gray values > 128 are turned to white (255)
# Gray values <= 128 are turned to black (0)
plot(img3)