• 请不要在回答技术问题时复制粘贴 AI 生成的内容
answer42
V2EX  ›  程序员

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

  •  
  •   answer42 · Mar 6, 2015 · 6251 views
    This topic created in 4276 days ago, the information mentioned may be changed or developed.

    代码

    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

    Supplement 1  ·  Mar 6, 2015
    ## 增加了参数说明

    * `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 replies  •  2015-03-08 10:36:24 +08:00
    47jm9ozp
    47jm9ozp
    Mar 6, 2015
    1
    颜色空间转换可以直接用opencv内部的吧……
    answer42
    answer42
    OP
    Mar 6, 2015
    2
    @ooxxcc 你指的是哪个过程中的颜色转换?
    answer42
    answer42
    OP
    Mar 6, 2015
    3
    @ooxxcc 你指的是哪个过程中的颜色空间转换?
    answer42
    answer42
    OP
    Mar 6, 2015
    4
    @ooxxcc 论文作者发布的代码只能够处理32位的图片,我增加了对8位图片的支持。
    zerh925
    zerh925
    Mar 6, 2015
    5
    如果是边缘没有这么明显的图片呢
    47jm9ozp
    47jm9ozp
    Mar 6, 2015
    6
    @answer42 啊,我说的是 RGB LAB XYZ等颜色空间转换

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

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

    对于边缘没那么明显的图片,你可以尝试增大超像素的个数。
    47jm9ozp
    47jm9ozp
    Mar 6, 2015
    9
    @answer42 转一下就好……

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

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

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

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

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

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

    简直坑
    ywisax
    ywisax
    Mar 7, 2015
    21
    必须star,太牛了
    answer42
    answer42
    OP
    Mar 7, 2015
    22
    @ooxxcc 所以说,做图像处理的想要在工业领域做出产品,太难了。

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

    -_-|||
    mantoka
    mantoka
    Mar 8, 2015❤️1
    23
    @answer42 这很正常啊,汽车行业许多保安件都要求做到1PPM,就是百万分之一。即使这样那1件残次品装车的后果也不堪设想。对于动辄上10W+的总量,99%的识别率毫无意义。这块还是依靠人工100%多批次检查来保证。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2496 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 10:54 · PVG 18:54 · LAX 02:54 · JFK 05:54
    ♥ Do have faith in what you're doing.