V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
answer42
V2EX  ›  程序员

V2EX 有做图像处理的同学吗?写了个 SLIC 超像素分割算法+OpenCV2 的类,简单易用~

  •  
  •   answer42 · 2015-03-06 15:00:03 +08:00 · 4806 次点击
    这是一个创建于 3339 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码

    github链接:np-csu/SLIC-superpixel

    Class explanation

    • void SLIC::GenerateSuperpixels(cv::Mat& img, UINT numSuperpixels)

      Perform SLIC algorithm on the given image with the given number of superpixels.

    • cv::Mat SLIC::GetImgWithContours(cv::Scalar color)

      Get the result image with contours on the given color.

    • int* SLIC::GetLabel()

      Get label on each pixel which shows the number of superpixel it belongs to.

    Example

    original image

    bird_color.jpg

    200 superpixels

    bird_color.jpg

    500 superpixels

    bird_color.jpg

    第 1 条附言  ·  2015-03-06 16:24:00 +08:00
    ## 增加了参数说明

    * `void SLIC::GenerateSuperpixels(cv::Mat& img, UINT numSuperpixels)`

    Perform SLIC algorithm on the given image with the given number of superpixels.

    `img` - 24-bit or 8-bit cv::Mat

    `numSuperpixels` - an appropriate number, no more than total number of pixels

    * `cv::Mat SLIC::GetImgWithContours(cv::Scalar color)`

    Get the result image with contours on the given color.

    `color` - If input image is 24-bit, the color may be cv::Scalar(255, 0, 0) or cv::Scalar(0, 255, 0) or cv::Scalar(0, 0, 255).

    If input image is 8-bit, the color may be cv::Scalar(0) or cv::Scalar(128) or cv::Scalar(255)
    23 条回复    2015-03-08 10:36:24 +08:00
    ooxxcc
        1
    ooxxcc  
       2015-03-06 15:12:45 +08:00
    颜色空间转换可以直接用opencv内部的吧……
    answer42
        2
    answer42  
    OP
       2015-03-06 15:37:18 +08:00
    @ooxxcc 你指的是哪个过程中的颜色转换?
    answer42
        3
    answer42  
    OP
       2015-03-06 15:37:43 +08:00
    @ooxxcc 你指的是哪个过程中的颜色空间转换?
    answer42
        4
    answer42  
    OP
       2015-03-06 15:39:53 +08:00
    @ooxxcc 论文作者发布的代码只能够处理32位的图片,我增加了对8位图片的支持。
    zerh925
        5
    zerh925  
       2015-03-06 17:01:54 +08:00
    如果是边缘没有这么明显的图片呢
    ooxxcc
        6
    ooxxcc  
       2015-03-06 17:06:41 +08:00
    @answer42 啊,我说的是 RGB LAB XYZ等颜色空间转换

    例如 RGB2XYZ RGB2LAB等,没仔细看代码,有错勿怪
    answer42
        7
    answer42  
    OP
       2015-03-06 17:23:50 +08:00
    @ooxxcc 是的,OpenCV自带一些颜色空间转换的函数,针对的是Mat格式。SLIC类中所带的转换函数针对的是unsigned int格式。
    answer42
        8
    answer42  
    OP
       2015-03-06 17:26:38 +08:00
    @zerh925 算法基于K均值聚类,提取像素的位置(x, y)以及像素的值(r, g, b)作为特征。

    在已有超像素分割算法中效果还是不错的。

    对于边缘没那么明显的图片,你可以尝试增大超像素的个数。
    ooxxcc
        9
    ooxxcc  
       2015-03-06 17:39:28 +08:00
    @answer42 转一下就好……

    C++: Mat::Mat(Size size, int type, void* data, size_t step=AUTO_STEP)

    opencv自带的一些函数有各种优化,一般我都直接用,就不自己造轮子了。。
    Valyrian
        10
    Valyrian  
       2015-03-06 18:15:43 +08:00
    computer vision课作业写过。。。
    ooxxcc
        11
    ooxxcc  
       2015-03-06 18:17:05 +08:00
    cv相关专业但是不知道为啥一直在做嵌入式学术上一事无成的飘过。。
    theoractice
        12
    theoractice  
       2015-03-06 19:51:39 +08:00
    看起来很好玩。想问下这个有啥应用呢?
    shakoon
        13
    shakoon  
       2015-03-06 20:34:02 +08:00
    看着很不错呢,楼主加油!
    jimmy66
        14
    jimmy66  
       2015-03-06 21:18:05 +08:00
    这学期在学,先star了
    answer42
        15
    answer42  
    OP
       2015-03-07 10:06:36 +08:00
    @Valyrian 这个难度确实适合大作业完成。今年带一个本科生做毕业设计,也是超像素分割。
    answer42
        16
    answer42  
    OP
       2015-03-07 10:09:07 +08:00
    @ooxxcc 现在我做的一个工业项目,也是相当尴尬。

    工业上对于图像识别的准确率,几乎要求100%。

    即使算法能够达到99%,也意味着100次操作会出现一次失误,而失误的代价是很大的。
    answer42
        17
    answer42  
    OP
       2015-03-07 10:11:57 +08:00
    @theoractice 超像素分割算法是图像预处理的一部分。

    它将相似邻近的像素抽象出来,视为一体。

    这样做一方面能够让我们更方便把握图像的纹理结构信息。另一方面,降低了后期算法的复杂度。
    answer42
        18
    answer42  
    OP
       2015-03-07 10:12:38 +08:00
    @shakoon 谢谢~
    answer42
        19
    answer42  
    OP
       2015-03-07 10:12:51 +08:00
    @jimmy66 嗯,多交流~
    ooxxcc
        20
    ooxxcc  
       2015-03-07 12:17:59 +08:00
    @answer42 金融机具相关,要求识别错误率小于万分之三,另一个指标是小于万分之零点五

    简直坑
    ywisax
        21
    ywisax  
       2015-03-07 15:44:21 +08:00
    必须star,太牛了
    answer42
        22
    answer42  
    OP
       2015-03-07 16:56:57 +08:00
    @ooxxcc 所以说,做图像处理的想要在工业领域做出产品,太难了。

    你看知乎这个问题: http://www.zhihu.com/question/22990970

    -_-|||
    mantoka
        23
    mantoka  
       2015-03-08 10:36:24 +08:00   ❤️ 1
    @answer42 这很正常啊,汽车行业许多保安件都要求做到1PPM,就是百万分之一。即使这样那1件残次品装车的后果也不堪设想。对于动辄上10W+的总量,99%的识别率毫无意义。这块还是依靠人工100%多批次检查来保证。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   902 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 21:10 · PVG 05:10 · LAX 14:10 · JFK 17:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.