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

在这里插入图片描述

⛄一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【图像分割】基于matlab HSV彩色空间图像分割【含Matlab源码 1474期】
(https://download.csdn.net/download/TIQCmatlab/62925370)
点击上面蓝色字体,直接付费下载,即可。

获取代码方式2:
付费专栏Matlab图像处理(初级版)

备注:
点击上面蓝色字体付费专栏Matlab图像处理(初级版),扫描上面二维码,付费29.9元订阅海神之光博客付费专栏Matlab图像处理(初级版),凭支付凭证,私信博主,可免费获得1份本博客上传CSDN资源代码(有效期为订阅日起,三天内有效);
点击CSDN资源下载链接:1份本博客上传CSDN资源代码

⛄二、图像分割简介

理论知识参考:【基础教程】基于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)QSQV + (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 ihalfR & jhalfR
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_fig1)
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_mark0
mid_Y1=mid_Y;
mid_Y2=Y;
change_mark=1;
elseif change_mark
1 & k<1
k=1;
elseif k1
%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’);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

⛄四、运行结果

在这里插入图片描述
在这里插入图片描述

⛄五、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]赵浩鹏,叶飞,麻之润,刘帅君.基于GrabCut和HSV彩色空间的三七叶片病斑图像分割[J].计算机与数字工程. 2021,49(10)

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

  • 12
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab领域

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值