- 积分
- 0
- 注册时间
- 2016-1-17
- 仿真币
-
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2016-6-27 17:29:52
|
显示全部楼层
来自 河南平顶山
clc;
clear;
close all;
I = imread('D:\Matlab处理图\10mm 30° 60mm.jpg');
% 提取R,G,B
I1 = I(:,:,1);
I2 = I(:,:,2);
I3 = I(:,:,3);
% 二值化R,G,B
J1 = im2bw(I1);
J2 = im2bw(I2);
J3 = im2bw(I3);
% 连通块分析R,G,B
[L1,num1] = bwlabel(J1);num1
[L2,num2] = bwlabel(J2);num2
[L3,num3] = bwlabel(J3);num3
% 显示
figure;
subplot(2,2,1);
imshow(I);
title('Origin')
subplot(2,2,2);
imshow(I1);
title('R')
subplot(2,2,3);
imshow(I2);
title('G')
subplot(2,2,4);
imshow(I3);
title('B')
figure;
subplot(2,3,1);
imshow(J1);
title('R-Gray')
subplot(2,3,2);
imshow(J2);
title('G-Gray')
subplot(2,3,3);
imshow(J3);
title('B-Gray')
subplot(2,3,4);
imshow(L1);
title('R-Label')
subplot(2,3,5);
imshow(L2);
title('G-Label')
subplot(2,3,6);
imshow(L3);
title('B-Label')
% 整合
L = [];
for i = 1:size(L1,1)
for j = 1 : size(L1,2)
temp = [L1(i,j) L2(i,j) L3(i,j)];
if temp == zeros(1,3)
L(i,j) = 0;
else
if L1(i,j)~= 0
L(i,j) = L1(i,j);
continue;
elseif L2(i,j) ~= 0
L(i,j) = L2(i,j);
continue;
elseif L3(i,j) ~= 0
L(i,j) = L3(i,j);
continue;
end
end
end
end
% 显示
figure;
imshow(L);
for color=1:num1
temp=I(I==color);
[label,n]=bwlabel(temp);
area=regionprops(label,'Area')
end
这个是网上找的命令不知道对不对
|
|