How can I turn picture to structured dataframe? [closed] - r

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I would like to classify pictures by using R software. I have no knowledge in image processing so it will be great if someone would point me to the right direction. First, how can I turn a picture that I have into a structured dataframe so I'll be able to analyze it? Is there a package for this task? Second, Is there a defined process for picture classification that I can follow?

With this lines you can load images in R and store them in a list.
library(jpeg)
setwd("path/to/folder/with/images/")
pics <- dir()
all_images <- NULL
for(z in pics){
all_images[[z]] <- readJPEG(z, native = T)
}
# check the first image in the list
plot(1:2, type='n')
rasterImage(all_images[[1]],1,1,2,2)
for processing images you can use the imager package.

Related

How to read a bulk number image files in R? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have more than 400 image files in my loacl directory.I want to read these images in r for passing it through XG boost algorithm..My two tries(codes) are is given below
library("EBImage")
img <- readImage("/home/vishnu/Documents/XG_boost_R/Data_folder/*.jpg")
and
library(jpeg)
library(biOps)
myjpg <- readJpeg("/home/vishnu/Documents/XG_boost_R/Data_folder/*.jpg")
It is a bit hard to guess what you want to do exactly, but one way to accomplish loading a lot of files and processing them is via a for-loop like this:
files <- list.files() #create a vector with file names
for(i in 1:length(files)){#loop over file names
load(files[i]) #load .rda-file
#do some processing and save results
}
This structure is generalizable to other cases. Depending on what kind of files you want to load, you will have to replace load(files[i]) with the appropriate command, for instance load.image() from the imager package.

How to print values from a dataframe at specific positions into a PDF? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a PDF form which needs to be filled out with data in df, one file per row, in the manner explained in the picture.
How can I create a printable area that contains the PDF as background, and prints each column of df on a specific position, namely, its corresponding field?
Thanks!
First we need to store in a pdf with filename "My File". If you want a different filename each time just loop. The "par(mfrow=...) will tell R the dimensions of the plot i.e.
pdf(paste("My File",".pdf",sep=""))
par(mfrow=c(1,1))
Then we can choose a plot to print with vertical and horizontal lines; if our df has dimensions nrow by ncol:
p1<-p2<-0
plot(p1,p2,type="n",xlim=c(0.19,4.78),ylim=c(0.252,5.75))
abline(v=c(1:4),h=c(1:5))
text((1/2)*seq(1,9,by=2),rep((1/2)*seq(1,11,2),each=6),c("P","R","I","N","T"),cex=5)
Although I highly recommend you just use a package if possible such as in this short video: https://www.youtube.com/watch?v=GOQ_StD4sGA

In R, find value in one CSV, isolate it in another [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm working on a project in R, regarding baseball. I have two CSV's that I'm working with. One file, CSV2: "PitchingPost.csv" is all postseason pitching stats, and the column I'm looking at there is the "teamID". I'm trying to evaluate regular season pitching stats in another file, CSV1: "pitching.csv" but only for teams that made the postseason. So I'm trying to remove all of the items in the "teamID" of CSV1 EXCEPT for those occur in CSV2 "teamID".
Help?
To keep only the rows from your first file that share an ID with rows in your second file, you could try something like that:
pitch <- read.csv("pitching.csv")
pitch_post <- read.csv("PitchingPost.csv")
pitch <- pitch[pitch$teamID %in% unique(pitch_post$teamID),]

How to read and write tiff image in R [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm new in R
can you give me some example code I need use to read and write tiff image in R
or just list the step
Thanks
Google is going to be your friend when learning R. It's old enough that everything is out there. :)
Tiff Package
To install this, you might want to try :
install.packages("tiff")
But if you want to use it put this at the top of each script
library("tiff")
To read and write I suggest :
writeTIFF(yourdatahere, getwd())
You don't assign a name to it because you are just outputting data at this point. Here is getting a TIFF.
TiffObject <- readTIFF(yourfile)
Make sure your file is in your working directory. You can set your working directory by doing :
setwd(path)
If you need anything else, just comment and I shall help.

passing a data frame to a function in R language [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to pass a data frame to a function as an argument. And then inside the function, I want to work on different combinations of columns for graphical presentation. Basically, I want to do graphical presentation on different data files. I want that, I pass the data file as an argument and then get the graphs. How can I do this in R.
You are not giving us much info but here is a very basic starting point:
library(ggplot2) # if you don't have this library run install.packages('ggplot2')
myAmazingFunction <- function(myDF) {
ggplot(myDF,aes(X,Y))+geom_line()
}
df <-data.frame(X=1:30, Y=runif(30), Z=1.3*runif(30))
myAmazingFunction(df)

Resources