SlideShare a Scribd company logo
Prepared by Volkan OBAN
Loading a picture (.png) on R
> library(png)
> img = readPNG("itu.png")
> if (exists("rasterImage")) { # can plot only in R 2.11.0 and higher
plot(1:2, type='n')
if (names(dev.cur()) == "windows") {
# windows device doesn't support semi-transparency so we'll need
# to flatten the image
transparent <- img[,,4] == 0
img <- as.raster(img[,,1:3])
img[transparent] <- NA
rasterImage(img, 1.2, 1.27, 1.8, 1.73, interpolate=FALSE)
} else {
# any reasonable device will be fine using alpha
rasterImage(img, 1.2, 1.27, 1.8, 1.73)
rasterImage(img.n, 1.5, 1.5, 1.9, 1.8)
}
}
Reference: https://github.com/dahtah/imager
http://dahtah.github.io/imager/gettingstarted.html
https://www.r-bloggers.com/new-package-for-image-processing-in-r/
http://stackoverflow.com/questions/15283447/how-to-read-jpeg-in-r-2-15
imager package in R
Example:
> library(imager)
> im <- load.image(system.file('extdata/parrots.png',package='imager'))
> layout(t(1:3))
> plot(im,main="Original image")
> grad <- grayscale(im) %>% get_gradient("xy")
> names(grad) <- paste("Gradient along",c("x","y"))
> l_ply(names(grad),function(n) plot(grad[[n]],main=n))
Example:
> library(imager)
> plot(boats)
> layout(t(1:2))
> plot(boats)
> plot(boats/2)
layout(t(1:2))
> boats.s <- boats/255 #scale to 0..1
> plot(boats.s,rescale=FALSE)
> plot(boats.s/2,rescale=FALSE)
> rgb(0,1,0)
[1] "#00FF00"
> cscale <- function(r,g,b) rgb(g,r,b)
> plot(boats.s,colourscale=cscale,rescale=FALSE)
> cscale <- scales::gradient_n_pal(c("red","purple","lightblue"),c(0,.5,1))
> #cscale is now a function returning colour codes
> cscale(0)
[1] "#FF0000"
> grayscale(boats) %>% plot(colourscale=cscale,rescale=FALSE)
> grayscale(boats) %>% plot(colourscale=cscale,rescale=FALSE)
> boats.g <- grayscale(boats)
> f <- ecdf(boats.g)
> plot(f,main="Empirical CDF of luminance values")
> f <- ecdf(boats.g)
> plot(f,main="Empirical CDF of luminance values")
> f(boats.g) %>% str
num [1:98304] 0.175 0.169 0.168 0.168 0.17 ...
> f(boats.g) %>% as.cimg(dim=dim(boats.g)) %>% plot(main="With histogram equalisation")
> gr <- imgradient(boats.g,"xy")
> plot(gr,layout="row")
> dx <- imgradient(boats.g,"x")
> dy <- imgradient(boats.g,"y")
> grad.mag <- sqrt(dx^2+dy^2)
> plot(grad.mag,main="Gradient magnitude")
library(ggplot2)
> df <- grayscale(boats) %>% as.data.frame
> p <- ggplot(df,aes(x,y))+geom_raster(aes(fill=value))
> p
> df <- as.data.frame(boats)
> p <- ggplot(df,aes(x,y))+geom_raster(aes(fill=value))+facet_wrap(~ cc)
> p+scale_y_reverse()
Example:
>hub <- load.example("hubble") %>% grayscale
> plot(hub,main="Hubble Deep Field")
Example:
fpath <- system.file('extdata/parrots.png',package='imager')
> parrots <- load.image(fpath)
> plot(parrots)
Example:
> library(imager)
> library(purrr)
> parrots <- load.example("parrots")
> plot(parrots)
> #Define a function that converts to YUV, blurs a specific channel, and co
nverts back
> bchan <- function(im,ind,sigma=5) {
+ im <- RGBtoYUV(im)
+ channel(im,ind) <- isoblur(channel(im,ind),sigma);
+ YUVtoRGB(im)
+ }
> #Run the function on all three channels and collect the results as a list
> blurred <- map_il(1:3,~ bchan(parrots,.))
> names(blurred) <- c("Luminance blur (Y)","Chrominance blur (U)","Chromina
nce blur (V)")
> plot(blurred

More Related Content

What's hot

Camera shots and angles
Camera shots and anglesCamera shots and angles
Camera shots and anglesemaanadnan
 
WORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTE
WORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTEWORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTE
WORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTERICARDO BARROS DE MIRANDA
 
Production Design
Production DesignProduction Design
Production Design
John Grace
 
Dont breathe analysis
Dont breathe analysisDont breathe analysis
Dont breathe analysis
catherinehjones
 
Projecto MultiméDia
Projecto MultiméDiaProjecto MultiméDia
Projecto MultiméDia
Nelson Sousa
 
Logotipos, isotipos, isologotipos
Logotipos, isotipos, isologotiposLogotipos, isotipos, isologotipos
Logotipos, isotipos, isologotipos
Katherine Sosa
 
Film poster analysis powerpoint
Film poster analysis powerpointFilm poster analysis powerpoint
Film poster analysis powerpoint
EllieSchool123
 
Anim2 Aula06 Sincronia
Anim2 Aula06 SincroniaAnim2 Aula06 Sincronia
Anim2 Aula06 Sincronia
profealbattaiola
 
Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...
Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...
Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...
Mulyani86
 
Guião
GuiãoGuião
Double page spreads for analysis
Double page spreads for analysisDouble page spreads for analysis
Double page spreads for analysisamybrackenridge
 
Concert Poster Analysis
Concert Poster AnalysisConcert Poster Analysis
Concert Poster Analysistaylapowell
 
Scream film poster analysis
Scream film poster analysisScream film poster analysis
Scream film poster analysisMollyBloxham
 
Analisis desain poster film
Analisis desain poster filmAnalisis desain poster film
Analisis desain poster film
StellaRanus14
 
Manual de Normas Gráficas Marca Pessoal
Manual de Normas Gráficas Marca PessoalManual de Normas Gráficas Marca Pessoal
Manual de Normas Gráficas Marca Pessoal
Viktoriya Limonova
 
Poster Review Harry Potter
Poster Review Harry PotterPoster Review Harry Potter
Poster Review Harry Pottersanchiaa
 
Pre-produção AV - Guiões Literários, Técnicos e Storyboard
Pre-produção AV - Guiões Literários, Técnicos e StoryboardPre-produção AV - Guiões Literários, Técnicos e Storyboard
Pre-produção AV - Guiões Literários, Técnicos e Storyboard
Pedro Almeida
 
Film Posters: Layout and Composition
Film Posters: Layout and CompositionFilm Posters: Layout and Composition
Film Posters: Layout and Composition
GeorginaGilbey
 
Projecto e Produção Multimédia
Projecto e Produção MultimédiaProjecto e Produção Multimédia
Projecto e Produção Multimédia
Goncalo
 
Graphic media language magazine double page spread analysis
Graphic media language magazine double page spread analysisGraphic media language magazine double page spread analysis
Graphic media language magazine double page spread analysis
RafaelPerezOlivan
 

What's hot (20)

Camera shots and angles
Camera shots and anglesCamera shots and angles
Camera shots and angles
 
WORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTE
WORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTEWORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTE
WORKSHOP DIREÇÃO DE PROGRAMAS DE TV 2ª PARTE
 
Production Design
Production DesignProduction Design
Production Design
 
Dont breathe analysis
Dont breathe analysisDont breathe analysis
Dont breathe analysis
 
Projecto MultiméDia
Projecto MultiméDiaProjecto MultiméDia
Projecto MultiméDia
 
Logotipos, isotipos, isologotipos
Logotipos, isotipos, isologotiposLogotipos, isotipos, isologotipos
Logotipos, isotipos, isologotipos
 
Film poster analysis powerpoint
Film poster analysis powerpointFilm poster analysis powerpoint
Film poster analysis powerpoint
 
Anim2 Aula06 Sincronia
Anim2 Aula06 SincroniaAnim2 Aula06 Sincronia
Anim2 Aula06 Sincronia
 
Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...
Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...
Branding yang berhasil membuat siapa pun pesaingmu nanti kesulitan menjadi sa...
 
Guião
GuiãoGuião
Guião
 
Double page spreads for analysis
Double page spreads for analysisDouble page spreads for analysis
Double page spreads for analysis
 
Concert Poster Analysis
Concert Poster AnalysisConcert Poster Analysis
Concert Poster Analysis
 
Scream film poster analysis
Scream film poster analysisScream film poster analysis
Scream film poster analysis
 
Analisis desain poster film
Analisis desain poster filmAnalisis desain poster film
Analisis desain poster film
 
Manual de Normas Gráficas Marca Pessoal
Manual de Normas Gráficas Marca PessoalManual de Normas Gráficas Marca Pessoal
Manual de Normas Gráficas Marca Pessoal
 
Poster Review Harry Potter
Poster Review Harry PotterPoster Review Harry Potter
Poster Review Harry Potter
 
Pre-produção AV - Guiões Literários, Técnicos e Storyboard
Pre-produção AV - Guiões Literários, Técnicos e StoryboardPre-produção AV - Guiões Literários, Técnicos e Storyboard
Pre-produção AV - Guiões Literários, Técnicos e Storyboard
 
Film Posters: Layout and Composition
Film Posters: Layout and CompositionFilm Posters: Layout and Composition
Film Posters: Layout and Composition
 
Projecto e Produção Multimédia
Projecto e Produção MultimédiaProjecto e Produção Multimédia
Projecto e Produção Multimédia
 
Graphic media language magazine double page spread analysis
Graphic media language magazine double page spread analysisGraphic media language magazine double page spread analysis
Graphic media language magazine double page spread analysis
 

Similar to imager package in R and examples..

ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
Dr. Volkan OBAN
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
zahid-mian
 
Genomic Graphics
Genomic GraphicsGenomic Graphics
Genomic Graphics
Dr. Volkan OBAN
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
Dr. Volkan OBAN
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemMaithreya Chakravarthula
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
Oswald Campesato
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
Oswald Campesato
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
500Tech
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
Mahmoud Samir Fayed
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
GCS2013
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202
Mahmoud Samir Fayed
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
Richard Jones
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
Vikas Sharma
 
Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화
Tae wook kang
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
Dr. Volkan OBAN
 
Chainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereportChainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereport
Preferred Networks
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
Dr. Volkan OBAN
 

Similar to imager package in R and examples.. (20)

ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
Genomic Graphics
Genomic GraphicsGenomic Graphics
Genomic Graphics
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
 
R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support System
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
WebXR if X = how?
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 
Chainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereportChainer ui v0.3 and imagereport
Chainer ui v0.3 and imagereport
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
 

More from Dr. Volkan OBAN

Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
Dr. Volkan OBAN
 
Covid19py Python Package - Example
Covid19py  Python Package - ExampleCovid19py  Python Package - Example
Covid19py Python Package - Example
Dr. Volkan OBAN
 
Object detection with Python
Object detection with Python Object detection with Python
Object detection with Python
Dr. Volkan OBAN
 
Python - Rastgele Orman(Random Forest) Parametreleri
Python - Rastgele Orman(Random Forest) ParametreleriPython - Rastgele Orman(Random Forest) Parametreleri
Python - Rastgele Orman(Random Forest) Parametreleri
Dr. Volkan OBAN
 
Linear Programming wi̇th R - Examples
Linear Programming wi̇th R - ExamplesLinear Programming wi̇th R - Examples
Linear Programming wi̇th R - Examples
Dr. Volkan OBAN
 
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ..."optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
Dr. Volkan OBAN
 
k-means Clustering in Python
k-means Clustering in Pythonk-means Clustering in Python
k-means Clustering in Python
Dr. Volkan OBAN
 
Naive Bayes Example using R
Naive Bayes Example using  R Naive Bayes Example using  R
Naive Bayes Example using R
Dr. Volkan OBAN
 
R forecasting Example
R forecasting ExampleR forecasting Example
R forecasting Example
Dr. Volkan OBAN
 
k-means Clustering and Custergram with R
k-means Clustering and Custergram with Rk-means Clustering and Custergram with R
k-means Clustering and Custergram with R
Dr. Volkan OBAN
 
Data Science and its Relationship to Big Data and Data-Driven Decision Making
Data Science and its Relationship to Big Data and Data-Driven Decision MakingData Science and its Relationship to Big Data and Data-Driven Decision Making
Data Science and its Relationship to Big Data and Data-Driven Decision Making
Dr. Volkan OBAN
 
Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.
Dr. Volkan OBAN
 
Scikit-learn Cheatsheet-Python
Scikit-learn Cheatsheet-PythonScikit-learn Cheatsheet-Python
Scikit-learn Cheatsheet-Python
Dr. Volkan OBAN
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet
Dr. Volkan OBAN
 
Pandas,scipy,numpy cheatsheet
Pandas,scipy,numpy cheatsheetPandas,scipy,numpy cheatsheet
Pandas,scipy,numpy cheatsheet
Dr. Volkan OBAN
 
ReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an exampleReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an example
Dr. Volkan OBAN
 
ReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an exampleReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an example
Dr. Volkan OBAN
 
R-ggplot2 package Examples
R-ggplot2 package ExamplesR-ggplot2 package Examples
R-ggplot2 package Examples
Dr. Volkan OBAN
 
R Machine Learning packages( generally used)
R Machine Learning packages( generally used)R Machine Learning packages( generally used)
R Machine Learning packages( generally used)
Dr. Volkan OBAN
 
treemap package in R and examples.
treemap package in R and examples.treemap package in R and examples.
treemap package in R and examples.
Dr. Volkan OBAN
 

More from Dr. Volkan OBAN (20)

Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
Conference Paper:IMAGE PROCESSING AND OBJECT DETECTION APPLICATION: INSURANCE...
 
Covid19py Python Package - Example
Covid19py  Python Package - ExampleCovid19py  Python Package - Example
Covid19py Python Package - Example
 
Object detection with Python
Object detection with Python Object detection with Python
Object detection with Python
 
Python - Rastgele Orman(Random Forest) Parametreleri
Python - Rastgele Orman(Random Forest) ParametreleriPython - Rastgele Orman(Random Forest) Parametreleri
Python - Rastgele Orman(Random Forest) Parametreleri
 
Linear Programming wi̇th R - Examples
Linear Programming wi̇th R - ExamplesLinear Programming wi̇th R - Examples
Linear Programming wi̇th R - Examples
 
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ..."optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
 
k-means Clustering in Python
k-means Clustering in Pythonk-means Clustering in Python
k-means Clustering in Python
 
Naive Bayes Example using R
Naive Bayes Example using  R Naive Bayes Example using  R
Naive Bayes Example using R
 
R forecasting Example
R forecasting ExampleR forecasting Example
R forecasting Example
 
k-means Clustering and Custergram with R
k-means Clustering and Custergram with Rk-means Clustering and Custergram with R
k-means Clustering and Custergram with R
 
Data Science and its Relationship to Big Data and Data-Driven Decision Making
Data Science and its Relationship to Big Data and Data-Driven Decision MakingData Science and its Relationship to Big Data and Data-Driven Decision Making
Data Science and its Relationship to Big Data and Data-Driven Decision Making
 
Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.Data Visualization with R.ggplot2 and its extensions examples.
Data Visualization with R.ggplot2 and its extensions examples.
 
Scikit-learn Cheatsheet-Python
Scikit-learn Cheatsheet-PythonScikit-learn Cheatsheet-Python
Scikit-learn Cheatsheet-Python
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet
 
Pandas,scipy,numpy cheatsheet
Pandas,scipy,numpy cheatsheetPandas,scipy,numpy cheatsheet
Pandas,scipy,numpy cheatsheet
 
ReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an exampleReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an example
 
ReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an exampleReporteRs package in R. forming powerpoint documents-an example
ReporteRs package in R. forming powerpoint documents-an example
 
R-ggplot2 package Examples
R-ggplot2 package ExamplesR-ggplot2 package Examples
R-ggplot2 package Examples
 
R Machine Learning packages( generally used)
R Machine Learning packages( generally used)R Machine Learning packages( generally used)
R Machine Learning packages( generally used)
 
treemap package in R and examples.
treemap package in R and examples.treemap package in R and examples.
treemap package in R and examples.
 

Recently uploaded

Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
vcaxypu
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
ewymefz
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
balafet
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
mbawufebxi
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
ArpitMalhotra16
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 

Recently uploaded (20)

Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 

imager package in R and examples..

  • 1. Prepared by Volkan OBAN Loading a picture (.png) on R > library(png) > img = readPNG("itu.png") > if (exists("rasterImage")) { # can plot only in R 2.11.0 and higher plot(1:2, type='n') if (names(dev.cur()) == "windows") { # windows device doesn't support semi-transparency so we'll need # to flatten the image transparent <- img[,,4] == 0 img <- as.raster(img[,,1:3]) img[transparent] <- NA rasterImage(img, 1.2, 1.27, 1.8, 1.73, interpolate=FALSE) } else { # any reasonable device will be fine using alpha rasterImage(img, 1.2, 1.27, 1.8, 1.73) rasterImage(img.n, 1.5, 1.5, 1.9, 1.8) } }
  • 3. Example: > library(imager) > im <- load.image(system.file('extdata/parrots.png',package='imager')) > layout(t(1:3)) > plot(im,main="Original image") > grad <- grayscale(im) %>% get_gradient("xy") > names(grad) <- paste("Gradient along",c("x","y")) > l_ply(names(grad),function(n) plot(grad[[n]],main=n))
  • 6. layout(t(1:2)) > boats.s <- boats/255 #scale to 0..1 > plot(boats.s,rescale=FALSE) > plot(boats.s/2,rescale=FALSE)
  • 7. > rgb(0,1,0) [1] "#00FF00" > cscale <- function(r,g,b) rgb(g,r,b) > plot(boats.s,colourscale=cscale,rescale=FALSE)
  • 8. > cscale <- scales::gradient_n_pal(c("red","purple","lightblue"),c(0,.5,1)) > #cscale is now a function returning colour codes > cscale(0) [1] "#FF0000" > grayscale(boats) %>% plot(colourscale=cscale,rescale=FALSE) > grayscale(boats) %>% plot(colourscale=cscale,rescale=FALSE)
  • 9. > boats.g <- grayscale(boats) > f <- ecdf(boats.g) > plot(f,main="Empirical CDF of luminance values") > f <- ecdf(boats.g) > plot(f,main="Empirical CDF of luminance values") > f(boats.g) %>% str num [1:98304] 0.175 0.169 0.168 0.168 0.17 ... > f(boats.g) %>% as.cimg(dim=dim(boats.g)) %>% plot(main="With histogram equalisation")
  • 10. > gr <- imgradient(boats.g,"xy") > plot(gr,layout="row")
  • 11. > dx <- imgradient(boats.g,"x") > dy <- imgradient(boats.g,"y") > grad.mag <- sqrt(dx^2+dy^2) > plot(grad.mag,main="Gradient magnitude")
  • 12. library(ggplot2) > df <- grayscale(boats) %>% as.data.frame > p <- ggplot(df,aes(x,y))+geom_raster(aes(fill=value)) > p
  • 13. > df <- as.data.frame(boats) > p <- ggplot(df,aes(x,y))+geom_raster(aes(fill=value))+facet_wrap(~ cc) > p+scale_y_reverse()
  • 14. Example: >hub <- load.example("hubble") %>% grayscale > plot(hub,main="Hubble Deep Field")
  • 15. Example: fpath <- system.file('extdata/parrots.png',package='imager') > parrots <- load.image(fpath) > plot(parrots)
  • 16. Example: > library(imager) > library(purrr) > parrots <- load.example("parrots") > plot(parrots) > #Define a function that converts to YUV, blurs a specific channel, and co nverts back > bchan <- function(im,ind,sigma=5) { + im <- RGBtoYUV(im) + channel(im,ind) <- isoblur(channel(im,ind),sigma); + YUVtoRGB(im) + } > #Run the function on all three channels and collect the results as a list > blurred <- map_il(1:3,~ bchan(parrots,.)) > names(blurred) <- c("Luminance blur (Y)","Chrominance blur (U)","Chromina nce blur (V)") > plot(blurred