-
大小: 3KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-29
- 語言: 其他
- 標簽: Normalized??Cut??
資源簡介
用Normalized Cut聚類方法實現 圖像分割,據說效果不錯,給大家做個參考

代碼片段和文件信息
function?W?=?CompW(data?sigS?sigR?radius)
%?COMPW?????compute?weight?matrix
%?
%?sigS??????spatial?sigma
%?sigR??????range?sigma
%?radius????radius?for?truncated?Gaussian?kernel
%?
%?W?????????weitht?matrix
%?
%?By?Jiarui?Ding?U?of?S
%?Nov?14?2007
%?Data?preparing?3D(color)?or?1D(grayscale)?plus?2D?spacial?feature
[mRows?nCols?d]?=?size(data);
%?
if?d==3
????cform?=?makecform(‘srgb2lab‘);
????ILab??=?applycform(data?cform);
????data??=?single(ILab);
end
data?=?single(data);
d?=?d+2;
[gridR?gridC]?=?ndgrid(?1:mRows?1:nCols?);
%?Normalize?spacial?and?range?kernel?size?to?1
spaGrid?=?cat(?3?gridR/sigS?gridC/sigS);?
data?=?cat(?3?spaGrid?data/sigR?);
N?=?mRows?*?nCols;
W?=?sparse(NN);
%?Improvement?exchange?the?order?of?the?two?for?loops?to?in?accordance?with
%?the?way?Matlab?indexing?matrix
for?i=1:mRows?
for?j=1:nCols
????????newMean?=?data(ij:);?
????????newMean?=?newMean(:)‘;
??????
????????%?Find?data?within?the?kernel?window
????????r?=?round(?newMean(1)*sigS?);??
????????c?=?round(?newMean(2)*sigS?);
????????????
????????%?Restrict?the?coordiates?in?the?domain?of?image?grid
????????rBound?=?max(1r-radius):min(mRowsr+radius);?
????????cBound?=?max(1c-radius):min(nColsc+radius);
????????
????????%?The?Row?and?Column?index
????????[rC?cC]?=?meshgrid(rBound?cBound);
????????idxC?=?sub2ind([mRows?nCols]?rC?cC);
????????idxC?=?reshape(idxC‘?length(rBound)?*?length(cBound)?1);
????????idxR?=?i?+?(j?-?1)?*?mRows;
????????
????????kernelWindow?=?data(?rBound?cBound?:?);
????????kernelWindow?=?reshape(?kernelWindow?[]?d?);?%?Get?a?d?dimential?vector?
????????%?Compute?weight??
????????n?=?size(?kernelWindow?1);
????????D?=?sum(?(repmat(newMean?n?1)?-?kernelWindow?).^2?2?);????????
????????value?=?exp(-D);
????????%?Get?weight?matrix
????????W(idxR?idxC)?=?value;????
????end
end
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1926??2007-12-03?17:40??Ncut\CompW.m
?????文件????????506??2007-11-17?21:49??Ncut\Ncut.m
?????文件???????1134??2007-12-03?17:40??Ncut\NcutSeg.m
?????文件???????1946??2007-12-03?17:40??Ncut\Segment.m
?????目錄??????????0??2011-04-21?22:13??Ncut
-----------?---------??----------?-----??----
?????????????????5512????????????????????5
評論
共有 條評論