by Davin Kaing
Drosophila Melanogaster is a species of fly commonly used in genetics study. A phenotype that is widely assessed in these studies is the eye damage. This report demonstrates the quantification of these damages using R programming.
library('reshape')
library('EBImage')
library("rgl")
library("scatterplot3d")
setwd("/Users/davinkaing/Desktop")
img1 = readImage("Image 1.png")
img2 = readImage("Image 2.png")
img1raster <- as.raster(img1)
img2raster <- as.raster(img2)
par(mfrow = c(2,2))
plot(img1raster)
plot(img2raster)
hist(img1, main = "Histogram of RGB for Healthy Eye", xlab = "Intensity", ylim = c(0,10000), axes = F)
abline(h = seq(0,10000, by = 2000), col = "lightgray")
par(new = T)
hist(img1, main = "Histogram of RGB for Healthy Eye", xlab = "Intensity", ylim = c(0,10000), axes = F)
axis(2, at = seq(0,10000, by = 2000), cex.axis = 0.8, las = 1)
axis(1, at = seq(0, 1, by = 0.2), cex.axis = 0.8, las = 1)
hist(img2, main = "Histogram of RGB for Damaged Eye", xlab = "Intensity", ylim = c(0,10000), axes = F)
abline(h = seq(0,10000, by = 2000), col = "lightgray")
par(new = T)
hist(img2, main = "Histogram of RGB for Damaged Eye", xlab = "Intensity", ylim = c(0,10000), axes = F)
axis(2, at = seq(0,10000, by = 2000), cex.axis = 0.8, las = 1)
axis(1, at = seq(0, 1, by = 0.2), cex.axis = 0.8, las = 1)
img_melt1 <- melt(img1)
img_melt2 <- melt(img2)
par(mfrow = c(2,2))
plot(img1raster)
plot(img2raster)
R1 <- img_melt1[img_melt1$X3==1, ]
G1 <- img_melt1[img_melt1$X3==2, ]
B1 <- img_melt1[img_melt1$X3==3, ]
A1 <- img_melt1[img_melt1$X3==4, ]
img_comb1 <- cbind(R1$value, G1$value, B1$value)
colors1 <- rgb(img_comb1[,1], img_comb1[,2], img_comb1[,3], alpha = A1$value)
scatterplot3d(img_comb1, color = colors1, xlab = "Red", ylab = "Green", zlab = "Blue",
main = "3D Plot of Healthy Eye", cex.axis = 0.5, cex.symbols = 0.1)
R2 <- img_melt2[img_melt2$X3==1, ]
G2 <- img_melt2[img_melt2$X3==2, ]
B2 <- img_melt2[img_melt2$X3==3, ]
A2 <- img_melt2[img_melt2$X3==4, ]
img_comb2 <- cbind(R2$value, G2$value, B2$value)
colors2 <- rgb(img_comb2[,1], img_comb2[,2], img_comb2[,3], alpha = A2$value)
scatterplot3d(img_comb2, color = colors2, xlab = "Red", ylab = "Green", zlab = "Blue",
main = "3D Plot of Damaged Eye", cex.axis = 0.5, cex.symbols = 0.1)
img_melt1 <- melt(img1)
img_melt2 <- melt(img2)
par(mfrow = c(2,2))
plot(img1raster)
plot(img2raster)
col_dom1 <- kmeans(img_comb1, centers = 5)
centerdata1 <- data.frame(cbind(col_dom1$centers, col_dom1$size))
centerdata1$rgb<- rgb(centerdata1$X1,centerdata1$X2, centerdata1$X3)
colnames(centerdata1) <- c("R", "G", "B", "Count", "RGB")
centerdata1$percent <- centerdata1$Count/sum(centerdata1$Count)*100
barplot(centerdata1$percent, col = centerdata1$RGB, ylim = c(0,100), ylab = "Percentage", main = "Dominant Colors of Healthy Eyes")
col_dom2 <- kmeans(img_comb2, centers = 5)
centerdata2 <- data.frame(cbind(col_dom2$centers, col_dom2$size))
centerdata2$rgb<- rgb(centerdata2$X1,centerdata2$X2, centerdata2$X3)
colnames(centerdata2) <- c("R", "G", "B", "Count", "RGB")
centerdata2$percent <- centerdata2$Count/sum(centerdata2$Count)*100
barplot(centerdata2$percent, col = centerdata2$RGB, ylim = c(0,100), ylab = "Percentage", main = "Dominant Colors of Damaged Eyes")