开发者

How to calculate the amount of "green spots" in an image?

Hi I have a bunch of images. Let's assume all of them of the same size. The images have a black background and some quasi round green spots which represent fluorescence. I have to calculate the amount (in percentage) of fluorescence of each image. I.e. the area of green spots.

Any idea how to do this, for e开发者_运维知识库xample in Java?


This is a standard problem in image processing, and is called image segmentation. You will be able to find vast quantities of information about it.

In particular, this is a common problem in microscopic image processing, which is what you're doing. I think there might be canned operations to do it in ImageJ; if not, it would be a fairly simple macro in ImageJ, and since ImageJ is in java, you could write java code using ImageJ's libraries if you like.

I would suggest an approach in which you:

  1. Preprocess the image to clean it up - background subtraction by subtracting a median filter or a gaussian convolution with a neighbourhood larger than your cells, or the rolling ball algorithm (look in the ImageJ source for that), or something similar, perhaps followed by a small amount of blurring (say, a median filter with a 3x3 neighbourhood) to remove speckles.
  2. Calculate a histogram of the image
  3. Search for two peaks in the histogram, one corresponding to black pixels, one to green
  4. Use the values of the two peaks to seed a two-cluster K-means (2-means, i suppose!) segmentation

Instead of doing the K-means step, you could just pick a threshold from the histogram (look for the valley between the two peaks, say), and segment on that. Or use some sort of adaptive segmentation (comparing pixels to the median in their neighbourhood, say), but that will require some tuning.


A few thoughts:

  • You could do an edge detection and then perform a hough circle transform. This should work well if you already know the radius of the circles.
  • When comparing colors you could use a color space that is better suited for fuzzy comparison. For example the HSV color space
  • Since your background is black, it is probably easiest to calculate the luminance and apply a threshold. Then count the pixels above the threshold.
  • When posting a computer-vision problem, it is always helpful to see the input material.


I don't have the time to go into detail now, but I can outline the process for you:

Loop through the images

  1. Load each image into a BufferedImage (http://download.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html)
  2. Loop through each pixel (x,y) and get the colour for that pixel (int getRGB(int x, int y))
  3. Compare this colour to your reference colour (e.g. 0x7FFF00 for green) or define a range of accepted colours.
  4. If it matches, increment a counter
  5. After the loop ran, compare the counter to the total number of pixels and et voila, you got your percentage

(NB: this is probably a very naive way to do it and there is loads of optimisation possible, but it should be a start)


You could e.g. use imagemagik, see http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=16177

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜