資源簡介
譜聚類算法對圖像進行分割的程序,可以直接運行,主程序為Demo,Demo_features,運行后可以對程序包中帶的圖片1和圖片2進行分割。

代碼片段和文件信息
%?This?code?implemented?a?搉ormalized-cut?segmentation?using?color?and?texture?information
%?This?code?segment?an?image?using?color?texture?and?spatial?data
%?RGB?color?is?used?as?an?color?data
%?Four?texture?features?are?used:?1.?mean?2.?variance?3.?skewness?4.?kurtosis
%?Normalized?Cut?(inherently?uses?spatial?data)
%?ncut?parameters?are?“SI“?Color?similarity?“ST“?Texture?similarity?“SX“?Spatial?similarity?“r“?Spatial?threshold?(less?than?r?pixels?apart)?“sNcut“?The?smallest?Ncut?value?(threshold)?to?keep?partitioning?and?“sArea“?The?smallest?size?of?area?(threshold)?to?be?accepted?as?a?segment?
%?an?implementation?by?“Naotoshi?Seo“?with?a?small?modification?is?used?for?搉ormalized-cut?segmentation?available?online?at:?“http://note.sonots.com/SciSoftware/NcutImageSegmentation.html“?It?is?sensitive?in?choosing?parameters.
%?Alireza?Asvadi
%?Department?of?ECE?SPR?Lab
%?Babol?(Noshirvani)?University?of?Technology
%?http://www.a-asvadi.ir
%?2013
%%?clear?command?windows
clc
clear?all
close?all
tic
%%?initialize
Im?=?imread(‘1.jpg‘);
[nRownColdim]?=?size(Im);??????????????%?Image?row?&?col
N??=?nRow*nCol;??????????????????????????%?Number?of?pixels
Vx?=?reshape(ImNdim);??????????????????%?Vertices?of?Graph
%?figure();?imshow(Im);
%%?Texture
m????=?1;????????????????????????????????%?window?width?for?texture?extraction?is?2*m+1
ST???=?10;???????????????????????????????%?texture?similarity
dim2?=?4;????????????????????????????????%?number?of?texture?features
In?=?im2double(rgb2gray(Im));
T?=?zeros(nRownColdim2);???????????????%?initialize?variance?image
for?i?=?1:nRow???????????????????????????%?central?pixel?(in?image?coordinate)??????????????????????????????
????for?j?=?1:nCol???
Vi??=?(i-floor(m)):(i+floor(m));?????????%%?neighbourhood?pixels?(in?image?coordinate)
Vj??=?((j-floor(m)):(j+floor(m)));
Vi??=?Vi(Vi>=1?&?Vi<=nRow);??????????????%?keep?pixels?that?are?inside?image
Vj??=?Vj(Vj>=1?&?Vj<=nCol);
blk?=?In(ViVj);?????????????????????????%%?image?block
T(ij1)?=?mean(blk(:));?????????????????%?mean
T(ij2)?=?var(blk(:));??????????????????%?variance
T(ij3)?=?skewness(blk(:));?????????????%?skewness
T(ij4)?=?kurtosis(blk(:));?????????????%?kurtosis
????end
end
T(::1)?=?(T(::1)-min(min(T(::1))))/(max(max(T(::1)))-min(min(T(::1))));
T(::2)?=?(T(::2)-min(min(T(::2))))/(max(max(T(::2)))-min(min(T(::2))));
T(::3)?=?(T(::3)-min(min(T(::3))))/(max(max(T(::3)))-min(min(T(::3))));
T(::4)?=?(T(::4)-min(min(T(::4))))/(max(max(T(::4)))-min(min(T(::4))));
T?=?uint8(255*T);????????????????????????%?normalization
%?figure();?imshow(T)
%%?Compute?weight?matrix?W
r??=?1.5;????????????????????????????????%?Spatial?threshold?(less?than?r?pixels?apart)
SI?=?5;??????????????????????????????????%?Color?similarity
SX?=?6;??????????????????????????????????%?Spatial?similarity
sNcut?=?0.22;????????????????????????????%?The?smallest?Ncut?value?(threshold)?to?keep?partitioning?
sArea?=?30;???????????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????3033??2013-09-15?06:42??NcutPartition.m
?????文件????????1374??2013-09-15?06:43??NcutValue.m
?????文件???????16869??2013-07-04?00:11??1.jpg
?????文件???????13507??2013-09-15?05:47??2.jpg
?????文件????????6803??2015-08-27?18:17??Demo.m
?????文件????????2462??2013-09-15?14:51??Demo_features.m
?????文件????????1307??2015-09-09?08:21??license.txt
- 上一篇:魔獸世界插件制作指南
- 下一篇:譜聚類算法對圖像進行分割
評論
共有 條評論