www.gusucode.com > IPCV_Eval_Kit_R2019a_0ce6858工具箱matlab程序源码 > IPCV_Eval_Kit_R2019a_0ce6858/code/demo_files/I2_00c_morph_iron.m

    clear all;clc;close all;imtool close all

%% 僆儕僕僫儖夋憸偺儘乕僪偲昞帵
Iorg=imread('I2_00c_iron.tif');
imtool(Iorg);      % 僐儞僩儔僗僩挷惍儊僯儏乕偱僸僗僩僌儔儉妋擣
%title('Original Image','Fontsize',12,'Fontweight','bold')

%% 2抣壔 (嫮搙儗儀儖180傪鑷抣偲偡傞丅崟偄慄傪慜宨偵)
I = Iorg<180; 
figure; imshow(I)
title('俀抣壔','Fontsize',12,'Fontweight','bold')

%% 嵶慄壔張棟(skel)
I = bwmorph(I,'skel','inf');
figure; imshow(I)
title('嵶慄壔','Fontsize',12,'Fontweight','bold')

%% 巬慄偺彍嫀(spur)
I = bwmorph(I,'spur','inf');
figure; imshow(I)
title('巬慄偺彍嫀','Fontsize',12,'Fontweight','bold')

%% 屒棫僆僽僕僃僋僩偺彍嫀(clean)
I = bwmorph(I,'clean');
figure; imshow(I)
title('屒棫僆僽僕僃僋僩偺彍嫀','Fontsize',12,'Fontweight','bold')

%% 斀揮
Ir=~I;
imshow(Ir);shg;

%% 奺椞堟傪屌桳偺斣崋偱儔儀儕儞僌乮攚宨偼 0乯
L = bwlabel(Ir,4);	% 奺椞堟傪屌桳偺斣崋偱儔儀儕儞僌 (4楢寢)
imtool(L);          % 奺椞堟偺抣傪妋擣

%% 儔儀儖斣崋枅偵怓暘偗
figure; imagesc(L); colormap(jet)
title('儔儀儕儞僌','Fontsize',12,'Fontweight','bold')

%% 僀儊乕僕偺椞堟夝愅 傾僾儕働乕僔儑儞

%% 椞堟僾儘僷僥傿偺應掕 (柺愊丒拞怱揰(廳怱))
stats = regionprops(L, 'Area', 'Centroid')

%% 堦斣栚偺椞堟偺應掕寢壥
stats(1)

%% 夋憸忋偵柺愊傪昞帵
hold on
for x = 1:length(stats)
	if stats(x).Area > 50	% 50僺僋僙儖埲忋偺椞堟偺傒昞帵
		xy = stats(x).Centroid;
        plot(xy(1), xy(2), 'r*');  %拞怱埵抲偵愒偺仏儅乕僋傪婰偡
		text(xy(1)+4, xy(2), num2str(stats(x).Area));
	end
end
hold off
title('僾儘僷僥傿嶼弌','Fontsize',12,'Fontweight','bold');shg;

%% 摑寁張棟
A = [stats.Area]     % 媮傑偭偨奺柺愊
%% 柺愊偺暯嬒
mean(A)
%% 僸僗僩僌儔儉昞帵
figure;hist(A)

%% 抂偑愗傟偰偄傞椞堟傪嶍彍
L1 = imclearborder(L,4);
figure;imagesc(L1),colormap(jet)

%% 
% Copyright 2014 The MathWorks, Inc.