Comments (3)
The problem with your code is that system.file()
is intended to provide file paths and names of files that are part of an R package. Hence, in your command i <- img_read(system.file("example_images", i, package = "imagefluency"))
you are telling R to search for the image high_1.jpg
(if i = 1
) in the subdirectory example_images
of the {imagefluency} package.
If you want to analyze images stored in a folder on your system, the following code should work.
library(imagefluency)
# make sure that the folder `example_images` is a subfolder of your current working directory
# to check the current working directory, use `getwd()`
# to change the current working directory, use `setwd()`
dir.exists("example_images/")
# define image list
imglist <- c("high_1.jpg", "high_2.jpg", "high_3.jpg", "high_4.jpg", "high_5.jpg", "high_6.jpg")
for (i in imglist) {
# read image (file path is constructed with `paste0()`)
img <- img_read(paste0("example_images/", i))
# calculate and print scores
print(data.frame(
img_complexity(img),
img_contrast(img),
mean(rgb2gray(img)),
img_self_similarity(img))
)
}
Alternatively, instead of constructing the file paths manually, a more elegant way would be to let R search for images in the example_images
folder.
# here, we only search for images with the extension .jpg
imglist <- list.files("example_images", pattern = '*.jpg$', full.names = TRUE)
for (i in imglist) {
# read image
img <- img_read(i)
# calculate and print scores
print(data.frame(
img_complexity(img),
img_contrast(img),
mean(rgb2gray(img)),
img_self_similarity(img))
)
}
If your goal is to store the results of all images in a data frame, then the following code can be used:
imglist <- list.files("example_images", pattern = '*.jpg$', full.names = TRUE)
# data frame to store results
results <- data.frame(filename = basename(imglist),
complexity = NA, contrast = NA,
mean = NA, selfsimilarity = NA)
# loop
for(i in seq_along(imglist)){
# print loop info
print(paste('** Estimating scores for image',i,'**'))
# 1. read image into R
img <- img_read(imglist[i])
# 2. estimate scores and store the results
results$complexity[i] <- img_complexity(img)
results$contrast[i] <- img_contrast(img)
results$mean[i] <- mean(rgb2gray(img))
results$selfsimilarity[i] <- img_self_similarity(img)
}
# print data frame
print(results)
from imagefluency.
Hello, thank you for your detailed answer. example_images folder is actually in the imagefluency folder in my computer. It's also in the R folder. I added my images to example_images folder but the code still did not work.
from imagefluency.
Related Issues (6)
- Error: Could not find shiny app directory. Try re-installing `imagefluency`. HOT 1
- Symmetry values differ based on the color of the image HOT 1
- Error: Invalid input (should be a matrix or a 3-dimensional array of numeric or integer values) HOT 4
- Images in getting started vignette are not displayed on github.io page
- Wrong code in batch-processing vignette
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagefluency.