-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage_Processing.R
More file actions
121 lines (90 loc) · 2.7 KB
/
Image_Processing.R
File metadata and controls
121 lines (90 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
rm(list=ls())
source("http://bioconductor.org/biocLite.R")
biocLite("EBImage")
# Black and white image
library(EBImage)
f <- system.file("images", "sample.png",package = "EBImage")
img <- readImage(f)
display(img)
f_c <- system.file("images", "sample-color.png",package = "EBImage")
imgc <- readImage(f_c)
display(imgc)
nuc <- readImage(system.file("images", "nuclei.tif",package = "EBImage"))
display(nuc)
# writing/saving the image
writeImage(imgc, 'imgc.jpeg', quality = 85)
# class of image
# multidimensional arrays with pixel intensities
class(imgc)
print(img)
############################# brightness control
img_br <- img + 0.2
display(img_br)
############################# contrast control
img_contst <- img*3
display(img_contst)
# ########################### gamma correction parameter
img_gamma <- (img+0.2)^3
display(img_gamma)
############################# transpose
img_t <- t(img)
display(img_t)
############################# threshold
img_thr <- img>0.5
display(img_thr)
############################# image crop
img_cr <- img[299:376, 224:301]
display(img_cr)
############################ multiple frames
imgcomb <- combine(img, img*2,img*3, img*4)
display(imgcomb)
print(imgc)
# color management
# Grayscale image with 3 frames
colorMode(imgc) <- Grayscale
display(imgc)
colorMode(imgc) <- Color
# image filtering
flo <- makeBrush(21, shape = 'disc', step = FALSE)^2
flo < flo/sum(flo)
imgflo <- filter2(imgc,flo)
display(imgflo)
fhi <- matrix(1, nc=3, nr=3)
fhi[2,2] = -8
imgfhi <- filter2(imgc,fhi)
display(imgfhi)
# Morphological oprations
# binary image
ei <- readImage(system.file('images','shapes.png',package = 'EBImage'))
ei <- ei[110:512, 1:130]
display(ei)
kern <- makeBrush(5, shape = 'diamond')
eierode <- erode(ei, kern)
display(eierode)
display(dilate(ei, kern))
# Segmentation
# bwlable for binary images and after thresholding
nuct <- nuc[,,1]>0.2
display(nuct)
nuclable <- bwlabel(nuct)
# number of nuclei:
max(nuclable)
# Adaptive thresholding
nuct2 <- thresh(nuc[,,1],w=10,h=10,offset = 0.05)
display(nuct2)
kern <- makeBrush(5, shape='disc')
nuct2 <- dilate(erode(nuct2, kern), kern)
display(nuct2)
nuclabel12 <- bwlabel(nuct2)
max(nuclabel12)
# object manipulation
bucgray <- channel(nuc[,,1],'rgb')
display(bucgray)
display(paintObjects(nuclabel12,bucgray, col='#ff00ff'))
nuclabel13 <- fillHull(nuclabel12)
display(paintObjects(nuclabel13,bucgray, col='#ff00ff'))
################# Image processing ###############################
cel <- readImage(system.file("images", "cells.tif",package = "EBImage"))
display(cel)
img <- rgbImage(green=1.5*cel, blue=nuc)
display(img)