图像处理之简单综合实例(大米计数) 您所在的位置:网站首页 米粒标志 图像处理之简单综合实例(大米计数)

图像处理之简单综合实例(大米计数)

2024-07-03 14:48| 来源: 网络整理| 查看: 265

图像处理之简单综合实例(大米计数)

一位网友给我发了几张灰度图像,说是他们单位的工业相机拍摄的,画质非常的清楚,他们

单位是农业科研单位,特别想知道种子的数量,他想知道的是每次工业相机拍摄种子图片中

有多少颗粒种子,想到了用图像处理的办法解决他们的问题,看了他给我照片,以大米种子

为例。实现了一个简单的算法流程,可以得到种子的数目。

大致算法分为以下三个步骤:

1.      将灰度图像二值化,二值化方法可以参考以前的文章,求取像素平均值,灰度直方图都

          可以

2.      去掉二值化以后的图像中干扰噪声。

3.      得到种子数目,用彩色标记出来。

源图像如下:

程序处理中间结果及最终效果如下:

二值化处理参见以前的文章 - http://blog.csdn.net/jia20003/article/details/7392325

大米计数与噪声块消去算法基于连通组件标记算法,源代码如下:

package com.gloomyfish.rice.analysis; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import com.gloomyfish.face.detection.AbstractBufferedImageOp; import com.gloomyfish.face.detection.FastConnectedComponentLabelAlg; public class FindRiceFilter extends AbstractBufferedImageOp { private int sumRice; public int getSumRice() { return this.sumRice; } @Override public BufferedImage filter(BufferedImage src, BufferedImage dest) { int width = src.getWidth(); int height = src.getHeight(); if ( dest == null ) dest = createCompatibleDestImage( src, null ); int[] inPixels = new int[width*height]; int[] outPixels = new int[width*height]; getRGB(src, 0, 0, width, height, inPixels ); FastConnectedComponentLabelAlg fccAlg = new FastConnectedComponentLabelAlg(); fccAlg.setBgColor(0); int[] outData = fccAlg.doLabel(inPixels, width, height); // labels statistic HashMap labelMap = new HashMap(); for(int d=0; d 16) & 0xff; tg = (inPixels[index] >> 8) & 0xff; tb = inPixels[index] & 0xff; if(outData[index] != 0 && validRice(outData[index], listKeys)) { tr = tg = tb = 255; } else { tr = tg = tb = 0; } outPixels[index] = (ta > 8) & 0xff; // tb = inPixels[index] & 0xff; srcrgb = inPixels[index] & 0x000000ff; if(srcrgb > 0 && row < 140) { tr = 0; tg = 255; tb = 0; } else if(srcrgb > 0 && row >= 140 && row 0 && row >=280) { tr = 255; tg = 0; tb = 0; } else { tr = tg = tb = 0; } outPixels[index] = (ta


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有