omarwagih / gitter

an R package for quantification of pinned microbial cultures
gitter.ccbr.utoronto.ca
4 stars 6 forks source link

Luminosity grey scale from GIMP #4

Closed chyutw closed 7 years ago

chyutw commented 7 years ago

Hi Omar

First of all, thanks for developing and maintaining the very useful R tool “gitter”. I am using it to analyze our microbial plate images. I just noticed that the Grayscales generated from gitter are a bit different than others.

After I checked the source code of gitter, I found there might be a problem in luminosity grey scale from GIMP. Here are some problematic lines in your main.R .readImage <- function(file){ n = basename(file) if(grepl('*.jpg$|*.jpeg$', file, ignore.case=T)){ return( readJPEG(file) ) }else if(grepl('*.tiff$', file, ignore.case=T)){ return( readTIFF(file) ) }else{ im = imageData( readImage(file) ) d = dim(im) M = array(NA, dim=d[c(2,1,3)]) M[,,1] = t(im[,,1]) if(d[3] > 1){ M[,,2] = t(im[,,2]) M[,,3] = t(im[,,3]) } return(M) } }

When it reads a JPEG or TIFF file by calling the function ” readJPEG”, the RGB order should be: 1:Red, 2: Green, 3:Blue

`# Extract greyscale if(is.color){ if(prog) setTxtProgressBar(pb, 9) loginfo('\tDetected color image, extracting greyscale')

Luminosity grey scale from GIMP

im.grey = (im[,,1]*0.72) + (im[,,2]*0.21) + (im[,,3]*0.07)
#im.grey = im[,,1]

}else{ loginfo('\tDetected greyscale image') im.grey = im

no color information

}`

Based on the Luminosity rule: https://en.wikipedia.org/wiki/Relative_luminance Luminosity = 0.21 × Red + 0.72 × Green + 0.07 × Blue so I suspected that the code here should be: im.grey = (im[,,1]*0.21) + (im[,,2]*0.72) + (im[,,3]*0.07)

Is this correct??

omarwagih commented 7 years ago

I remember the order being otherwise, but yes you're right that should be the correct order. I have pushed an update, this won't be on CRAN for a while so if you want the updated version you'll have to install from gihub: devtools::install_github("omarwagih/gitter") Thanks for picking this up!