惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
V
V2EX
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Y
Y Combinator Blog
小众软件
小众软件
Jina AI
Jina AI
V2EX - 技术
V2EX - 技术
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
The Hacker News
The Hacker News
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
T
Threatpost
博客园 - 聂微东
Scott Helme
Scott Helme
IT之家
IT之家
N
Netflix TechBlog - Medium
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
MongoDB | Blog
MongoDB | Blog
T
Tor Project blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
A
About on SuperTechFans
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CERT Recently Published Vulnerability Notes
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
C
Check Point Blog
L
LINUX DO - 最新话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
Attack and Defense Labs
Attack and Defense Labs
T
Tailwind CSS Blog
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Webroot Blog
Webroot Blog
Help Net Security
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
PCI Perspectives
PCI Perspectives
Security Latest
Security Latest

博客园 - 凤凰_1

多边形近似:最小周长多边形算法MPP 多阈值otsu的opencv实现 在Opencv中自定义了一个相位函数,获取复数矩阵的相位 cvIsInf与cvIsNan函数 Mandelbrot set 以parallel_for_实现 opencv的并行操作parallel_for_的问题 CV_WRAP和CV_EXPORTS_W opencv中自定义的双线性二次插值的图像旋转及缩放 在Qt中,如何在sheets末端添加新的sheet opencv4.x 中的plot函数绘制二维Mat C++版DNN最简主体框架 C++版全连接神经网络 C++版加载MNIST图像集合 C++版的神经网络训练用的图像集合加载 c\c++宏定义,四个参数求最大值 - 凤凰_1 - 博客园 自定义c++二维动态数组 用Cmake 编译OpenCV常见的错误 Opencv中的dft()和idft()示例 C++仿Matlab的bsxfun函数
opencv超级像素示例
凤凰_1 · 2024-05-26 · via 博客园 - 凤凰_1
/*
 * createSuperpixelLSC(cv::InputArray img,int region_size,float ratio)
其中各个参数意义如下:
    image:输入图像
    region_size :平均超像素大小,默认10
    ratio:超像素紧凑度因子,默认0.075
*/
void superpixelLSC(const Mat& img)
{
    cv::Ptr<cv::ximgproc::SuperpixelLSC> lsc=cv::ximgproc::createSuperpixelLSC(img);
    lsc->iterate(10);
    Mat labels;
    lsc->enforceLabelConnectivity();
//    int numOfSuperpixels=lsc->getNumberOfSuperpixels();
//    cout<<"numOfSuperpixels="<<numOfSuperpixels<<endl;
    lsc->getLabels(labels);
    Mat mask_lsc;
    lsc->getLabelContourMask(mask_lsc);//获取像素分割边界映射图,该图与原图像一样尺寸
    Mat mask_inv_lsc;
    cv::bitwise_not(mask_lsc,mask_inv_lsc);//将分割边界映射图按位取反
    Mat imgSeg;
    cv::bitwise_and(img,img,imgSeg,mask_inv_lsc);//将边界映射图叠加到原图像上
    imshow(" segmentation",imgSeg);
}
/*
 * ximgproc::createSuperpixelSLIC(cv::inputArray image, int algorithm=SLICO, int region_size,float ruler    )
其中各个参数意义如下:
   image :输入图像
   algorithm:选择要使用的算法变体:SLIC、SLICO(默认)和MSLIC三种可选
   region_size:平均超像素大小,默认10
   ruler:超像素平滑度,默认10
*/
void superpixelSLIC(const Mat&img)
{
    //初始化slic项,超像素平均尺寸20(默认为10),平滑因子20
    Mat imgLab;
    cvtColor(img,imgLab,COLOR_BGR2Lab);
    cv::Ptr<cv::ximgproc::SuperpixelSLIC> slic=cv::ximgproc::createSuperpixelSLIC(imgLab,cv::ximgproc::SLIC,20,20);
    slic->iterate(10);//迭代次数,越大效果越好
    Mat mask_slic,mask_inv_slic,label_slic;
    slic->getLabelContourMask(mask_slic);//获取Mask,超像素边缘Mask==1
    cv::bitwise_not(mask_slic,mask_inv_slic);
    Mat imgSeg;
    cv::bitwise_and(img,img,imgSeg,mask_inv_slic);
    slic->getLabels(label_slic);//获取超像素标签
    imshow("SLIC segmentation",imgSeg);
//    int numOfSuperpixels=slic->getNumberOfSuperpixels();
//    cout<<"numOfSuperpixels="<<numOfSuperpixels<<endl;


}
/*
 * createSuperpixelSEEDS(int image_width,int image_height, int image_channels,
 *                       int num_superpixels,int prior
其中各个参数意义如下:
    image_width :输入图像宽度
    image_height: 输入图像高度
    image_channels :输入图像通道数
    num_superpixels :期望超像素数目
    num_levels :块级别数,值越高,分段越准确,形状越平滑,但需要更多的内存和CPU时间。
    histogram_bins: 直方图bins数,默认5
    double_step: 如果为true,则每个块级别重复两次以提高准确性默认false。

原文链接:https://blog.csdn.net/qq_40268412/article/details/103915197
*/
void superpixelSeeds(const Mat&img)
{
    int num_superpixels=2000;
    int num_levels=3;
    cv::Ptr<cv::ximgproc::SuperpixelSEEDS> seeds=
            cv::ximgproc::createSuperpixelSEEDS(img.cols,img.rows,img.channels()
                                                 ,num_superpixels,num_levels);
    Mat mask_seeds,mask_inv_seeds,label_seeds,img_seeds;
    seeds->iterate(img,10);
    seeds->getLabels(label_seeds);
    seeds->getLabelContourMask(mask_seeds);
    cv::bitwise_not(mask_seeds,mask_inv_seeds);
    cv::bitwise_and(img,img,img_seeds,mask_inv_seeds);
    cout<<"label_seeds.channels()="<<mask_seeds.channels()<<endl;
    cout<<"label_seeds.size="<<mask_seeds.size()<<endl;
    imshow("seeds image",img_seeds);
}

int main()
{
    Mat img=imread("D:/Qt/MyImage/baboon.jpg",1);

    superpixelSeeds(img);
//    superpixelLSC(img);


    waitKey();
    return 0;
}