Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image processing/color detection in R: what library should I use?

I'm doing some image processing, and while I think I have a pretty good idea of my approach, I'm not having much luck finding which library(s) I should use to do this specifically in R.

I have a large database of similar images, each of which have an arbitrary number of variously-sized colored blobs on a white-ish background. I ultimately want to find the red, green, and blue values and calculate average RGB brightness across all colored pixels in all images from a particular date. This means being able to somehow differentiate colored pixels from near-white pixels and store their values.

I think what I want to do is create color histograms for a number of test images, look at the histograms' peaks to determine thresholds for what constitutes a "white" or "colored" pixel, then loop over the pixels in each image to find the colored ones matching my threshold(s) (I do know how to read in an image and get the pixel RGB values).

In my preferred language, Python, it sounds like I'd use the histogram method from the Image module in PIL, but I don't know the R equivalent (this may just be a weak point in my google-fu; search results are mostly for "R" as in "red" rather than the language. I did find this: R: Histogram, but I'm at a loss for whether it's relevant/how to use it).

If there might be a better approach from the domain of signal/image processing, I'd love to hear that, too.

TL;DR: How can I make a color histogram of an image, or otherwise select pixels of certain color values, using R?

(Related but not R-specific: How to calculate the amount of "green spots" in an image?)

like image 392
Beekguk Avatar asked Mar 30 '11 16:03

Beekguk


2 Answers

There is also an R interface to ImageJ (which I used once in a distance past, it's excellent image classification software written in Java) via the Bio7 package.

Other links for more information:

http://www.r-bloggers.com/image-data-and-classification-with-r/

http://www.r-bloggers.com/plots-in-r-and-the-imagej-visualization/

http://www.r-bloggers.com/image-classification-limits-part-2/

like image 191
Ari B. Friedman Avatar answered Sep 27 '22 20:09

Ari B. Friedman


there is an excellent 'rimage' package on CRAN.

try this:

library(rimage)
x <- read.jpeg(system.file("data", "cat.jpg", package="rimage"))
par(mfrow=c(1,3))
hist(x[,,1])
hist(x[,,2])
hist(x[,,3])
like image 23
kohske Avatar answered Sep 27 '22 20:09

kohske