首页 > 编程知识 正文

【图像分割】基于matlab HSV彩色空间图像分割【含Matlab源码 1474期】

时间:2023-05-04 14:33:39 阅读:109745 作者:1477

一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【图像分割】基于matlab HSV彩色空间图像分割【含Matlab源码 1474期】

获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、图像分割简介

理论知识参考:【基础教程】基于matlab图像处理图像分割【含Matlab源码 191期】

三、部分源代码 clear allRGB = imread('capsicum.bmp');figure(1);imshow(RGB);imwrite(RGB,'分割结果capsicum.jpg','jpg');HSV = rgb2hsv(RGB); % Transform from RGB to HSVH = 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 quantizationQH = 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 Hfor i = 1:QH k = find((H < i*scopeH) & (H >= (i-1)*scopeH)); HHH(k) = i;end% Quantize Sfor i = 1:QS k = find((S < i*scopeS) & (S >= (i-1)*scopeS)); SSS(k) = i;end% Quantize Vfor i = 1:QV k = find((V < i*scopeV) & (V >= (i-1)*scopeV)); VVV(k) = iend% Color labelQI = temp; % label matrix, used to statistic Ckfor 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); endendeQI = 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;%optimizestep = 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 loopaccuYTrue = 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_wldgb=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_wldgb==0 mid_Y1=mid_Y; mid_Y2=Y; change_wldgb=1; elseif change_wldgb==1 & k<1 k=1; elseif k==1 %if mid_Y1==mid_Y & mid_Y2==Y invar_fig=0; %else % change_wldgb=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 loopendfigure(57);Y_pcnn = uint8(Y_threshold)imshow(Y_pcnn);imwrite(Y_pcnn,'分割结果capsicum_pcnn_segm2.bmp','bmp');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 四、运行结果


五、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] yldfd.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]tmdsmt,无奈的世界,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]xqdbl.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]赵勇,dqdjz,顺心的机器猫,王侃伟.基于量子粒子群优化算法的最小交叉熵多阈值图像分割[J].计算机应用研究. 2008,(04)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。