This is an R HTML document. When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

source("http://bioconductor.org/biocLite.R")
## Bioconductor version 3.6 (BiocInstaller 1.28.0), ?biocLite for help
## A new version of Bioconductor is available after installing the most
##   recent version of R; see http://bioconductor.org/install
biocLite("EBImage")
## BioC_mirror: https://bioconductor.org
## Using Bioconductor 3.6 (BiocInstaller 1.28.0), R 3.4.4 (2018-03-15).
## Installing package(s) 'EBImage'
## 
## The downloaded binary packages are in
## 	/var/folders/s0/9n2cbr990tlgz463qjf1ymmm0000gn/T//RtmpqEQkUV/downloaded_packages
## Old packages: 'highr', 'later'
library("EBImage")
library(webshot)
## 
## Attaching package: 'webshot'
## The following object is masked from 'package:EBImage':
## 
##     resize

You can also embed plots, for example:

## Display a single image
x = readImage("~/Desktop/Dataset2/q.tif")
display(x, method ="raster",all = TRUE)
plot of chunk unnamed-chunk-3
imageData(x)[1:6]
## [1] 0.0000000 0.2039216 0.2392157 0.2235294 0.2313725 0.2980392
u <- channel(x,"gray")
display(u)
plot of chunk unnamed-chunk-3
imageData(u)[1:6]
## [1] 0.00000000 0.06797386 0.07973856 0.07450980 0.07712418 0.09934641
## Display a thresholded sequence ...

threshold = otsu(u)
z = combine( mapply(function(frame, th) frame > th, getFrames(u), threshold, SIMPLIFY=FALSE) )
display(z, all=TRUE)
plot of chunk unnamed-chunk-3
## ... using the interactive viewer ...
display(z, all = TRUE)

## ... or using R's build-in raster device
display(z, method = "raster", all = TRUE)

## Display the last frame 
display(z, method = "raster", frame = numberOfFrames(z, type = "render"))

## Customize grid appearance
s = readImage("~/Desktop/Dataset2/r.tif")
display(s, method = "raster", all = TRUE,
        nx = 2, spacing = 0.05, margin = 20, bg = "black")
plot of chunk unnamed-chunk-3
## Adaptive Thresholding
disc = makeBrush(31, "disc")
disc = disc / sum(disc)
offset = 0.05
nuc_bg = filter2( z, disc )
nuc_z = z > nuc_bg + offset
display(nuc_z, all=TRUE)
display( thresh(z, w=15, h=15, offset=0.05), all=TRUE )
plot of chunk unnamed-chunk-3
## Image Segmentation
  # Watershed algorithm treats a grayscale image as a topographic map
wshed = watershed( distmap(nuc_z), 2 )
display(colorLabels(wshed), method = "raster",all=TRUE)
plot of chunk unnamed-chunk-3
  # Voronoi tesselation shows a set of seed points or regions (assigns points in the space closest to each seed)
r = readImage("~/Desktop/Dataset2/q.tif")
c = readImage("~/Desktop/Dataset2/q.tif")
cc = rgbImage(red=c, blue=r)
display(cc, method = "raster", all = TRUE)
plot of chunk unnamed-chunk-3
  # Segment nuclei using thresh (removes attributes), fillHull (fills holes), bwlabel
n = thresh(r, w=10, h=10, offset=0.05)
n = opening(n, makeBrush(5, shape='disc'))
n = fillHull(n)
n = bwlabel(n)

display(n, all=TRUE)
plot of chunk unnamed-chunk-3
    # Same thing as before this time show the cytoplasm of the cells
i = channel(c,"gray")
y = opening(i>0.1, makeBrush(5, shape='disc'))
yxy = propagate(
  seeds = n, x = n , mask = n, lambda = 100)

yy = channel(yxy,"gray")

display(y, all=TRUE)
plot of chunk unnamed-chunk-3
## Segmentation
segmented2 = paintObjects(yy, c, col='#ff00ff')
segmented = paintObjects(yy, c, col='#ff00ff')
nn = channel(n,"gray")
segmented = paintObjects(nn, segmented, col='green')

display(segmented2, all=TRUE)
plot of chunk unnamed-chunk-3
display(segmented, all=TRUE)
plot of chunk unnamed-chunk-3
#
#
#



## Image 2

## Display a single image
x2 = readImage("~/Desktop/Dataset2/p.tif")
display(x2, method ="raster",all = TRUE)
plot of chunk unnamed-chunk-3
imageData(x2)[1:6]
## [1] 0.1803922 0.1843137 0.1882353 0.1490196 0.1686275 0.1411765
u2 <- channel(x2,"gray")
display(u2)
plot of chunk unnamed-chunk-3
imageData(u2)[1:6]
## [1] 0.06013072 0.06143791 0.06274510 0.04967320 0.05620915 0.04705882
## Display a thresholded sequence ...

threshold = otsu(u2)
z2 = combine( mapply(function(frame, th) frame > th, getFrames(u2), threshold, SIMPLIFY=FALSE) )
display(z2, all=TRUE)
plot of chunk unnamed-chunk-3
## ... using the interactive viewer ...
display(z2, all = TRUE)

## ... or using R's build-in raster device
display(z2, method = "raster", all = TRUE)

## Display the last frame 
display(z2, method = "raster", frame = numberOfFrames(z2, type = "render"))

## Customize grid appearance
display(s, method = "raster", all = TRUE,
        nx = 2, spacing = 0.05, margin = 20, bg = "black")
plot of chunk unnamed-chunk-3
## Adaptive Thresholding
disc2 = makeBrush(31, "disc")
disc2 = disc2 / sum(disc2)
offset = 0.05
nuc_bg2 = filter2( z2, disc )
nuc_z2 = z2 > nuc_bg2 + offset
display(nuc_z2, all=TRUE)
display( thresh(z2, w=15, h=15, offset=0.05), all=TRUE )
plot of chunk unnamed-chunk-3
## Image Segmentation
  # Watershed algorithm treats a grayscale image as a topographic map
wshed2 = watershed( distmap(nuc_z2), 2 )
display(colorLabels(wshed2), method = "raster",all=TRUE)
plot of chunk unnamed-chunk-3
  # Voronoi tesselation shows a set of seed points or regions (assigns points in the space closest to each seed)
r2 = readImage("~/Desktop/Dataset2/p.tif")
c2 = readImage("~/Desktop/Dataset2/p.tif")
cc2 = rgbImage(red=c2, blue=r2)
display(cc2, method = "raster", all = TRUE)
plot of chunk unnamed-chunk-3
  # Segment nuclei using thresh (removes attributes), fillHull (fills holes), bwlabel
n2 = thresh(r2, w=10, h=10, offset=0.05)
n2 = opening(n2, makeBrush(5, shape='disc'))
n2 = fillHull(n2)
n2 = bwlabel(n2)

display(n2, all=TRUE)
plot of chunk unnamed-chunk-3
    # Same thing as before this time show the cytoplasm of the cells
i2 = channel(c2,"gray")
y2 = opening(i2>0.1, makeBrush(5, shape='disc'))
yxy2 = propagate(
  seeds = n2, x = n2 , mask = n2, lambda = 100)

yy2 = channel(yxy2,"gray")

display(y2, all=TRUE)
plot of chunk unnamed-chunk-3
## Segmentation
segmente = paintObjects(yy2, c2, col='#ff00ff')
segmentedd = paintObjects(yy2, c2, col='#ff00ff')
nn2 = channel(n2,"gray")
segmentedd = paintObjects(nn2, segmented, col='green')

display(segmente, all=TRUE)
plot of chunk unnamed-chunk-3
display(segmentedd, all=TRUE)
plot of chunk unnamed-chunk-3
## Images being Compared:
display(segmented)
plot of chunk unnamed-chunk-3
display(segmentedd)
plot of chunk unnamed-chunk-3
Img1 <- segmented
data1 <- imageData(Img1)
data1[1:6]
## [1] 0.0000000 0.2039216 0.2392157 0.2235294 0.2313725 0.2980392
Img2 <- segmentedd
data2 <- imageData(Img2)
data2[1:6]
## [1] 0.0000000 0.2039216 0.2392157 0.2235294 0.2313725 0.2980392
## t test of matrices based on p-value > 0.05

t.test(data1[1:640], data2[1:640], paired = TRUE)
## 
## 	Paired t-test
## 
## data:  data1[1:640] and data2[1:640]
## t = 2.1147, df = 639, p-value = 0.03484
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.00038121 0.01029281
## sample estimates:
## mean of the differences 
##              0.00533701
mat1 <- cbind(Image1 = (1:640))
boxplot(mat1, main = "Image 1",
        notch = TRUE, col = 1:640)
plot of chunk unnamed-chunk-3
mat2 <- cbind(Image1 = (1:640))
boxplot(mat2, main = "Image 2",
        notch = TRUE, col = 1:640)
plot of chunk unnamed-chunk-3
## matrix.t.test(x, MARGIN = 1, n1 = if (MARGIN == 1) floor(ncol(x)/2) else floor(nrow(x)/2), n2 = if (MARGIN == 1) ncol(x) - n1 else nrow(x) - n1, pool = TRUE, pOnly=TRUE, tOnly = FALSE)
## thing <- mapply(1:ncol(mat1), function(x){
  # t.test(mat1[ ,x], mat2[ ,x])
# })

## boxplot(x, use.cols = TRUE, ...)