91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 198KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-16
  • 語言: C/C++
  • 標簽: superpixel??

資源簡介

slic超像素分割方法源代碼。c++實現,簡潔明了

資源截圖

代碼片段和文件信息

#include?“slic.h“

/*
?*?Constructor.?Nothing?is?done?here.
?*/
Slic::Slic()?{

}

/*
?*?Destructor.?Clear?any?present?data.
?*/
Slic::~Slic()?{
????clear_data();
}

/*
?*?Clear?the?data?as?saved?by?the?algorithm.
?*
?*?Input?:?-
?*?Output:?-
?*/
void?Slic::clear_data()?{
????clusters.clear();
????distances.clear();
????centers.clear();
????center_counts.clear();
}

/*
?*?Initialize?the?cluster?centers?and?initial?values?of?the?pixel-wise?cluster
?*?assignment?and?distance?values.
?*
?*?Input?:?The?image?(IplImage*).
?*?Output:?-
?*/
void?Slic::init_data(IplImage?*image)?{
????/*?Initialize?the?cluster?and?distance?matrices.?*/
????for?(int?i?=?0;?i?width;?i++)?{?
????????vector?cr;
????????vector?dr;
????????for?(int?j?=?0;?j?height;?j++)?{
????????????cr.push_back(-1);
????????????dr.push_back(FLT_MAX);
????????}
????????clusters.push_back(cr);
????????distances.push_back(dr);
????}
????
????/*?Initialize?the?centers?and?counters.?*/
????for?(int?i?=?step;?i?width?-?step/2;?i?+=?step)?{
????????for?(int?j?=?step;?j?height?-?step/2;?j?+=?step)?{
????????????vector?center;
????????????/*?Find?the?local?minimum?(gradient-wise).?*/
????????????CvPoint?nc?=?find_local_minimum(image?cvPoint(ij));
????????????CvScalar?colour?=?cvGet2D(image?nc.y?nc.x);
????????????
????????????/*?Generate?the?center?vector.?*/
????????????center.push_back(colour.val[0]);
????????????center.push_back(colour.val[1]);
????????????center.push_back(colour.val[2]);
????????????center.push_back(nc.x);
????????????center.push_back(nc.y);
????????????
????????????/*?Append?to?vector?of?centers.?*/
????????????centers.push_back(center);
????????????center_counts.push_back(0);
????????}
????}
}

/*
?*?Compute?the?distance?between?a?cluster?center?and?an?individual?pixel.
?*
?*?Input?:?The?cluster?index?(int)?the?pixel?(CvPoint)?and?the?Lab?values?of
?*?????????the?pixel?(CvScalar).
?*?Output:?The?distance?(double).
?*/
double?Slic::compute_dist(int?ci?CvPoint?pixel?CvScalar?colour)?{
????double?dc?=?sqrt(pow(centers[ci][0]?-?colour.val[0]?2)?+?pow(centers[ci][1]
????????????-?colour.val[1]?2)?+?pow(centers[ci][2]?-?colour.val[2]?2));
????double?ds?=?sqrt(pow(centers[ci][3]?-?pixel.x?2)?+?pow(centers[ci][4]?-?pixel.y?2));
????
????return?sqrt(pow(dc?/?nc?2)?+?pow(ds?/?ns?2));
????
????//double?w?=?1.0?/?(pow(ns?/?nc?2));
????//return?sqrt(dc)?+?sqrt(ds?*?w);
}

/*
?*?Find?a?local?gradient?minimum?of?a?pixel?in?a?3x3?neighbourhood.?This
?*?method?is?called?upon?initialization?of?the?cluster?centers.
?*
?*?Input?:?The?image?(IplImage*)?and?the?pixel?center?(CvPoint).
?*?Output:?The?local?gradient?minimum?(CvPoint).
?*/
CvPoint?Slic::find_local_minimum(IplImage?*image?CvPoint?center)?{
????double?min_grad?=?FLT_MAX;
????CvPoint?loc_min?=?cvPoint(center.x?center.y);
????
????for?(int?i?=?center.x-1;?i?????????for?(int?j?=?center.y-1;?j?????????????CvScalar?c1?=?cvGet2D

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-05-12?20:32??SLIC-Superpixels-master\
?????文件?????????611??2013-05-12?20:32??SLIC-Superpixels-master\README.md
?????文件??????164271??2013-05-12?20:32??SLIC-Superpixels-master\dog.png
?????文件???????57263??2013-05-12?20:32??SLIC-Superpixels-master\dog_segmentation.png
?????文件???????12759??2013-05-12?20:32??SLIC-Superpixels-master\slic.cpp
?????文件????????2515??2013-05-12?20:32??SLIC-Superpixels-master\slic.h
?????文件????????1217??2013-05-12?20:32??SLIC-Superpixels-master\test_slic.cpp

評論

共有 條評論