資源簡介
各種基于形狀特征的檢索方法都可以比較有效地利用圖像中感興趣的目標來進行檢索,本代碼是用matlab寫的,親測有效

代碼片段和文件信息
function?shape_recognition_demo1
try
clc;?%?Clear?the?command?window.
close?all;?%?Close?all?figures?(except?those?of?imtool.)
workspace;?%?Make?sure?the?workspace?panel?is?showing.
fontSize?=?15;
%?For?reference?compute?the?theoretical?circularity?of?a?bunch?of?regular?polygons
%?with?different?number?of?sides?starting?with?3?(triangle).
dividingValues?=?PlotTheoreticalCircularity;
%?Make?the?last?dividing?value?infinity?because?any?circularity?from?.99999?up?to?inifinity?should?be?a?circle.
%?and?sometimes?you?have?a?circularity?more?than?1?due?to?quantization?errors.
dividingValues(end)?=?inf;
%?Now?create?a?demo?image.
[binaryImage?numSidesCircularity]?=?CreateDemoImage();
%?Count?the?number?of?shapes
[~?numShapes]?=?bwlabel(binaryImage);
%?Display?the?polygon?demo?image.
subplot(1?2?1);
imshow(binaryImage);
caption?=?sprintf(‘Image?with?%d?Shapes‘?numShapes);
title(caption?‘FontSize‘?fontSize);
hold?on;?%?So?that?text?labels?won‘t?blow?away?the?image.
%?Set?up?figure?properties:
%?Enlarge?figure?to?full?screen.
set(gcf?‘Units‘?‘Normalized‘?‘OuterPosition‘?[0?0?1?1]);
%?Get?rid?of?tool?bar?and?pulldown?menus?that?are?along?top?of?figure.
set(gcf?‘Toolbar‘?‘none‘?‘Menu‘?‘none‘);
%?Give?a?name?to?the?title?bar.
set(gcf?‘Name‘?‘Demo?by?ImageAnalyst‘?‘Numbertitle‘?‘Off‘)
drawnow;?%?Make?it?display?immediately.
[labeledImage?numberOfobjects]?=?bwlabel(binaryImage);
blobMeasurements?=?regionprops(labeledImage?‘Perimeter‘?‘Area‘?‘Centroid‘?‘Image‘);
%?Now?compute?the?number?of?vertices?by?looking?at?the?number?of?peaks?in?a?plot?of?distance?from?centroid.
numSidesDistance?=?FindNumberOfVertices(blobMeasurements?labeledImage);
%?Get?all?the?measurements?into?single?arrays?for?convenience.
allAreas?=?[blobMeasurements.Area];
allPerimeters?=?[blobMeasurements.Perimeter];
circularities?=?(4?*?pi?*??allAreas)?./?allPerimeters.^2
%?Sort?in?order?of?increasing?circularity
[sortedCircularities?sortOrder]?=?sort(circularities?‘Ascend‘);
%?Sort?all?the?measurements?in?the?same?way.
blobMeasurements?=?blobMeasurements(sortOrder);
allAreas?=?allAreas(sortOrder);
allPerimeters?=?allPerimeters(sortOrder);
numSidesDistance?=?numSidesDistance(sortOrder);
%?Plot?a?bar?chart?of?the?circularities.
subplot(1?2?2);
bar(sortedCircularities);
ylim([0.55?1.1]);
grid?on;
title(‘Actual?Measured?Circularities‘?‘FontSize‘?fontSize);
%?Let‘s?compute?areas?a?different?way.??The?“Area“?returned?by?regionprops?is?a?count?of?the?number?of?pixels.
%?This?sometimes?overestimates?the?area.??Let‘s?use?bwarea?which?computes?the?area?on?a
%?pixel-center?to?pixel?center?basis.
for?k?=?1?:?numberOfobjects
thisBlob?=?blobMeasurements(k).Image;
allBwAreas(k)?=?bwarea(thisBlob);
end
bwCircularities?=?(4?*?pi?*??allBwAreas)?./?allPerimeters.^2
sortedCircularities?=?bwCircularities
%?Put?up?red?horizontal?line
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????21361??2018-03-28?15:25??形狀特征提取\shape_recognition_demo1.m
?????文件??????21361??2018-03-28?15:26??形狀特征提取\shape_recognition_demo2.m
?????目錄??????????0??2018-03-28?15:53??形狀特征提取
-----------?---------??----------?-----??----
????????????????42722????????????????????3
評論
共有 條評論