图像处理/颜色检测R:我应该用什么库?

时间:2023-02-05 11:22:33

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.

我有一个类似图像的大数据库,每一个都有一个白色背景上任意大小的彩色斑点。我最终希望找到红色、绿色和蓝色的值,并计算所有图像中所有彩色像素的平均RGB亮度。这意味着能够以某种方式区分彩色像素和接近白色的像素,并存储它们的值。

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).

我想我要做的是创建颜色直方图的测试图片,看直方图的峰值来确定阈值对什么是“白色”或“彩色”像素,然后遍历每个图像的像素发现颜色的匹配我的阈值(s)(我知道如何阅读一个图像和像素的RGB值)。

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).

在我喜欢的语言中,Python,听起来就像在PIL的图像模块中使用直方图方法,但是我不知道R等价(这可能只是我的google-fu中的一个弱点;搜索结果主要是“R”,而不是语言。我确实发现了这个:R:直方图,但我不知道它是否相关/如何使用。

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?

DR:我如何使用R来创建一个图像的颜色直方图,或者选择特定颜色值的像素?

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

(相关而非R-specific:如何计算图像中“绿色斑点”的数量?)

2 个解决方案

#1


5  

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.

还有一个用于ImageJ的R接口(我曾经用过一次,它是用Java编写的优秀的图像分类软件),通过Bio7包。

Other links for more information:

更多信息的其他链接:

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

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/plots-in-r-and-the-imagej-visualization/

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

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

#2


4  

there is an excellent 'rimage' package on CRAN.

在CRAN上有一个很好的“rimage”包。

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])

#1


5  

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.

还有一个用于ImageJ的R接口(我曾经用过一次,它是用Java编写的优秀的图像分类软件),通过Bio7包。

Other links for more information:

更多信息的其他链接:

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

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/plots-in-r-and-the-imagej-visualization/

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

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

#2


4  

there is an excellent 'rimage' package on CRAN.

在CRAN上有一个很好的“rimage”包。

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])