# R/ColorB.R In rwang14/implant: A High-throughput Phenotyping Pipeline for Image Processing and Functional Growth Curve Analysis

#### Documented in ColorB

```ColorB = function(image, colThreshold = 0.5, colTol = c(5, 5), EGThreshold = 0.075, changefromub = rep(0.1, 3),
changeto = c(1, 1, 1)){
#Find the main back bars, if flas[,]== TRUE, then transfer into 1 (white) in later steps
#changefromub is the threshold level of the black bar(each pixel)
flas = (image[, , 1] < changefromub) & (image[, ,2] < changefromub)  & (image[, ,3] < changefromub)
N = dim(image)
#Keep the black for the bin in the middle
flas[ , floor(5 * N / 12) : floor(7 * N / 12) ] = FALSE
#select the whole columns that contain black bars, see imagekbbb.png
index0 = which((colMeans(flas) > colThreshold) == 1)
#Find the edges of the black bars part, I think colTol might just be a random small number
index = c(max(index0[index0 < N / 2]) + colTol, min(index0[index0 > N / 2]) - colTol)
#select the left hand side that you want to erase
flas[, c(1 : index)] = TRUE
#select the right hand side that you want to erase
flas[, c(index : N)] = TRUE
imageR = image[, , 1]; imageG = image[, , 2]; imageB = image[, , 3]
#imagesum = imageR + imageG + imageB
#EG = (2 * imageG - imageR - imageB) / sqrt(6)
#flasGreen = (EG < EGThreshold * imagesum)
#flasGreen[, c((index + 1) : (index - 1))] = FALSE
#flas = flas & flasGreen
imageR[flas] = changeto
imageG[flas] = changeto
imageB[flas] = changeto
image[, , 1] = imageR; image[, , 2] = imageG; image[, , 3] = imageB
#lb means the left bound of the image that does not contain the black bars
#rb means the right bound of the image that does not contain the black bars
res = list(lb = index, rb = index, c = image)
return(res)
}
```
rwang14/implant documentation built on Dec. 9, 2019, 6:36 p.m.