【图像分割】基于matlab HSV彩色空间图像分割【含Matlab源码 1474期】
        【摘要】 
                    
                        
                    
                    一、获取代码方式 
获取代码方式1: 完整代码已上传我的资源:【图像分割】基于matlab HSV彩色空间图像分割【含Matlab源码 1474期】 
获取代码方式2: 通过订阅紫极神光博客付费专栏,凭支...
    
    
    
    一、获取代码方式
获取代码方式1:
 完整代码已上传我的资源:【图像分割】基于matlab HSV彩色空间图像分割【含Matlab源码 1474期】
获取代码方式2:
 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
备注:
 订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、图像分割简介
理论知识参考:【基础教程】基于matlab图像处理图像分割【含Matlab源码 191期】
三、部分源代码
clear all
RGB = imread('capsicum.bmp');
figure(1);
imshow(RGB);
imwrite(RGB,'分割结果\capsicum.jpg','jpg');
HSV = rgb2hsv(RGB); % Transform from RGB to HSV
H = HSV(:,:,1);
%figure(2);
%imshow(H);
S = HSV(:,:,2);
%figure(3);
%imshow(S);
V = HSV(:,:,3);
%figure(4);
%imshow(V);
H = H+0.22;
INDEX = find(H>1);
H(INDEX) = H(INDEX) - 1;
%figure(24);
%imshow(H);
imwrite(H,'分割结果\capsicum_H_revolve.jpg','jpg');
% Color quantization
QH = 32;
QS = 4;
QV = 2;
scopeH = 1 / QH;
scopeS = 1 / QS;
scopeV = 1 / QV;
siz = size(H);
M = siz(1) * siz(2);
temp = zeros(siz);
HHH = temp;
SSS = temp;
VVV = temp;
% Quantize H
for i = 1:QH
    k = find((H < i*scopeH) & (H >= (i-1)*scopeH));
    HHH(k) = i;
end
% Quantize S
for i = 1:QS
    k = find((S < i*scopeS) & (S >= (i-1)*scopeS));
    SSS(k) = i;
end
% Quantize V
for i = 1:QV
    k = find((V < i*scopeV) & (V >= (i-1)*scopeV));
    VVV(k) = i
end
% Color label
QI = temp;         % label matrix, used to statistic Ck
for i = 1:siz(1)
    for j = 1:siz(2)
        QI(i,j) = (HHH(i,j) -1)*QS*QV + (SSS(i,j) - 1)*QV + VVV(i,j);
    end
end
eQI = uint8(QI);
figure(36);
imshow(eQI);
imwrite(eQI,'分割结果\capsicum_quantitation.jpg','jpg');
%imwrite(eQI,['Lajiao_VQofHSV','.bmp'],'bmp');
%figure(112);
%EDG2 = edge(eQI,'canny');
%imshow(EDG2);
%imwrite(EDG2,['Lajiao_VQofHSV_edg','.bmp'],'bmp');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Double PCNN
%%%link parameter%%
[row, col] = size(QI);
Va = max(max(QI));
Vb = min(min(QI));
F = QI;
vl = 1;
vt = 500;
l_deta = 1;
l_t = 0.5;
link_a = l_deta*1 / l_t;
beta = 0.01;
t_deta = 1;
t_t = 25;
threshold = t_deta*1 / t_t;
%step = 20;%optimize
step = 18;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TEMP=zeros(row,col);
%%%%%%%%%%% to create W %%%%%%%%%%%%%%
%Ws=[0 1 0;1 1 1;0 1 0];
%%%%%%%%%%%%%%%%%%%%%
 radius=9;
 halfR = round(radius/2);
 deta = 2;
 for i = 1:radius
    for j = 1:radius
     if i==halfR & j==halfR
          K_r(halfR, halfR)=1;
          K_r2(halfR, halfR)=1;
       else
         K_r(i,j) = 1/sqrt((i-halfR)^2 + (j-halfR)^2);        
      end
    end
 end
 Ws = K_r;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% start program %%%%%%%%%%%%%
%%%% factor loop %%%%%
Y_threshold = TEMP;
Y_time = TEMP;
Y1 = TEMP;
Y2 = TEMP;
Y = TEMP;
Ya = TEMP;
Yb = TEMP;
Edge_image=TEMP;
L = TEMP;
U = TEMP;
T1 = TEMP + Va;
T2 = TEMP + Vb;
j = 1;
   
%%% determine when exit loop
accuYTrue = 1;
iterTrue = 1;
accY = TEMP;  % Accumulate total neuros of firing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while iterTrue
    j   
    L = link24(Y,L,Ws,link_a,vl);
    invar_fig=1;change_mark=0;k=0;
    %%%%%%%%%%%%%%%
     m=1;%% fast linking %%
     while (invar_fig==1)
          m
          mid_Y=Y;
          U=internal24(F,L,Y,beta);
          Y1 = pulse1(U, T1);
          %Y2 = pulse2(U, T2);
          Y = Y1; % + Y2;
          %Y=pulse_p(U,T,L);
          if (mid_Y==Y) 
             invar_fig=0;
          elseif m>30 & change_mark==0
             mid_Y1=mid_Y;
             mid_Y2=Y;
             change_mark=1;
          elseif change_mark==1 & k<1
             k=1;
          elseif k==1
             %if mid_Y1==mid_Y & mid_Y2==Y
                invar_fig=0;
                %else
               % change_mark=0;k=0;
               % end
          end
       
      end
    %%%%save threshold for fired pixels (sigle-pass)%%%%%%
    %%%%%%%statistc numbers of nurons in plusing areas %%%%%%
    index1 = find(Y1 ~= 0);%find index of element of noequal zero(index of pulsing neurons)
    q = size(index1, 1);     
    if q ~= 0     %%% statistic pulsing neurons %%%
        for yy = 1:row
            for zz = 1:col
                if(Y1(yy, zz) == 1)
                    Y_threshold(yy, zz) = round(T1(yy, zz));
                    Y_time(yy, zz) = j;
                end
            end
        end   %%% statistic end %%%
    end
    Ya = Ya + Y1;
    T1 = threshold1(T1, Ya, Va, step);  %decrement threshold(linear decay)%%%%%%%%%%
    j=j+1;
    %%%%%%%%%%%%%%%%%%%%%
    accY = accY + Y;
    index = find(accY == 0);
    size(index);
    if ans(1) == 0
        iterTrue = 0;
    end                       % Exit loop
end
figure(57);
Y_pcnn = uint8(Y_threshold)
imshow(Y_pcnn);
imwrite(Y_pcnn,'分割结果\capsicum_pcnn_segm2.bmp','bmp');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
 - 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 - 22
 - 23
 - 24
 - 25
 - 26
 - 27
 - 28
 - 29
 - 30
 - 31
 - 32
 - 33
 - 34
 - 35
 - 36
 - 37
 - 38
 - 39
 - 40
 - 41
 - 42
 - 43
 - 44
 - 45
 - 46
 - 47
 - 48
 - 49
 - 50
 - 51
 - 52
 - 53
 - 54
 - 55
 - 56
 - 57
 - 58
 - 59
 - 60
 - 61
 - 62
 - 63
 - 64
 - 65
 - 66
 - 67
 - 68
 - 69
 - 70
 - 71
 - 72
 - 73
 - 74
 - 75
 - 76
 - 77
 - 78
 - 79
 - 80
 - 81
 - 82
 - 83
 - 84
 - 85
 - 86
 - 87
 - 88
 - 89
 - 90
 - 91
 - 92
 - 93
 - 94
 - 95
 - 96
 - 97
 - 98
 - 99
 - 100
 - 101
 - 102
 - 103
 - 104
 - 105
 - 106
 - 107
 - 108
 - 109
 - 110
 - 111
 - 112
 - 113
 - 114
 - 115
 - 116
 - 117
 - 118
 - 119
 - 120
 - 121
 - 122
 - 123
 - 124
 - 125
 - 126
 - 127
 - 128
 - 129
 - 130
 - 131
 - 132
 - 133
 - 134
 - 135
 - 136
 - 137
 - 138
 - 139
 - 140
 - 141
 - 142
 - 143
 - 144
 - 145
 - 146
 - 147
 - 148
 - 149
 - 150
 - 151
 - 152
 - 153
 - 154
 - 155
 - 156
 - 157
 - 158
 - 159
 - 160
 - 161
 - 162
 - 163
 - 164
 - 165
 - 166
 - 167
 - 168
 - 169
 - 170
 - 171
 - 172
 - 173
 - 174
 - 175
 - 176
 - 177
 - 178
 - 179
 - 180
 - 181
 - 182
 - 183
 - 184
 - 185
 - 186
 - 187
 - 188
 - 189
 - 190
 - 191
 - 192
 - 193
 - 194
 - 195
 - 196
 - 197
 - 198
 - 199
 - 200
 - 201
 
四、运行结果

 
五、matlab版本及参考文献
1 matlab版本
 2014a
2 参考文献
 [1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
 [2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
 [3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
 [4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
 [5]赵勇,方宗德,庞辉,王侃伟.基于量子粒子群优化算法的最小交叉熵多阈值图像分割[J].计算机应用研究. 2008,(04)
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/121087558
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)