• 大小: 2.06MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-21
  • 语言: Html/CSS
  • 标签: 图像处理  tube  

资源简介

详情可见 https://www.cnblogs.com/l2017/p/9898512.html

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include“bwlable.h“
using namespace std;
using namespace cv;


//——————————【两步法新改进版】———————————————-
// 对二值图像进行连通区域标记从1开始标号
void  Two_PassNew(const Mat &bwImg Mat &labImg)
{
assert(bwImg.type() == CV_8UC1);
labImg.create(bwImg.size() CV_32SC1);   //bwImg.convertTo( labImg CV_32SC1 );
labImg = Scalar(0);
labImg.setTo(Scalar(1) bwImg);
assert(labImg.isContinuous());
const int Rows = bwImg.rows - 1 Cols = bwImg.cols - 1;
int label = 1;
vector labelSet;
labelSet.push_back(0);
labelSet.push_back(1);
//the first pass
int *data_prev = (int*)labImg.data;   //0-th row : int* data_prev = labImg.ptr(i-1);
int *data_cur = (int*)(labImg.data + labImg.step); //1-st row : int* data_cur = labImg.ptr(i);
for (int i = 1; i < Rows; i++)
{
data_cur++;
data_prev++;
for (int j = 1; j {
if (*data_cur != 1)
continue;
int left = *(data_cur - 1);
int up = *data_prev;
int neighborLabels[2];
int cnt = 0;
if (left>1)
neighborLabels[cnt++] = left;
if (up > 1)
neighborLabels[cnt++] = up;
if (!cnt)
{
labelSet.push_back(++label);
labelSet[label] = label;
*data_cur = label;
continue;
}
int smallestLabel = neighborLabels[0];
if (cnt == 2 && neighborLabels[1] smallestLabel = neighborLabels[1];
*data_cur = smallestLabel;
// 保存最小等价表
for (int k = 0; k {
int tempLabel = neighborLabels[k];
int& oldSmallestLabel = labelSet[tempLabel];  //这里的&不是取地址符号而是引用符号
if (oldSmallestLabel > smallestLabel)
{
labelSet[oldSmallestLabel] = smallestLabel;
oldSmallestLabel = smallestLabel;
}
else if (oldSmallestLabel labelSet[smallestLabel] = oldSmallestLabel;
}
}
data_cur++;
data_prev++;
}
//更新等价队列表将最小标号给重复区域
for (size_t i = 2; i < labelSet.size(); i++)
{
int curLabel = labelSet[i];
int prelabel = labelSet[curLabel];
while (prelabel != curLabel)
{
curLabel = prelabel;
prelabel = labelSet[prelabel];
}
labelSet[i] = curLabel;
}
//second pass
data_cur = (int*)labImg.data;
for (int i = 0; i < Rows; i++)
{
for (int j = 0; j < bwImg.cols - 1; j++ data_cur++)
*data_cur = labelSet[*data_cur];
data_cur++;
}
}

//———————————【颜色标记程序】———————————–
//彩色显示
cv::Scalar GetRandomColor()
{
uchar r = 255 * (rand() / (1.0 + RAND_MAX));
uchar g = 255 * (rand() / (1.0 + RAND_MAX));
uchar b = 255 * (rand() / (1.0 + RAND_MAX));
return cv::Scalar(b g r);
}


void LabelColor(const cv::Mat& labelImg cv::Mat& colorLabelImgint& asd )
{
int idf = 1;
int num = 0;
if (labelImg.empty() ||
labelImg.type() != CV_32SC1)
{
return;
}

std::map

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-02 13:09  Detached-moving-objects-master\
     文件       20036  2018-11-02 13:09  Detached-moving-objects-master\1.png
     文件        2462  2018-11-02 13:09  Detached-moving-objects-master\2.png
     文件       27424  2018-11-02 13:09  Detached-moving-objects-master\3.png
     文件       12820  2018-11-02 13:09  Detached-moving-objects-master\4.png
     文件       11274  2018-11-02 13:09  Detached-moving-objects-master\5.png
     文件         861  2018-11-02 13:09  Detached-moving-objects-master\README.md
     目录           0  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\
     目录           0  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\
     文件        1291  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\deived_tubes.log
     目录           0  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\deived_tubes.tlog\
     文件        1668  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\deived_tubes.tlog\CL.command.1.tlog
     文件       10312  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\deived_tubes.tlog\CL.read.1.tlog
     文件        1336  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\deived_tubes.tlog\CL.write.1.tlog
     文件         189  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\deived_tubes.tlog\deived_tubes.lastbuildstate
     文件      158720  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\vc140.idb
     文件      176128  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\Debug\vc140.pdb
     文件        3807  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\bwlable.cpp
     文件         272  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\bwlable.h
     文件        1868  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\deived_tube.h
     文件        1305  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\deived_tubes.sln
     文件        7166  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\deived_tubes.vcxproj
     文件        1431  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\deived_tubes.vcxproj.filters
     文件         165  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\deived_tubes.vcxproj.user
     文件         582  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\fillhole.cpp
     文件         177  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\fillhole.h
     文件        3578  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\main.cpp
     目录           0  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\x64\
     目录           0  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\x64\Release\
     文件     1725901  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\x64\Release\bwlable.obj
     文件        5200  2018-11-02 13:09  Detached-moving-objects-master\deived_tubes\x64\Release\deived_tube.obj
............此处省略16个文件信息

评论

共有 条评论

相关资源