新建个ff.m文件:
%% MATLAB R2013afunction feature = ff(im)
rot = @(t)[cos(t) -sin(t) sin(t) cos(t)]
im = ~im2bw(im)
Size = size(im)
CC = bwconncomp(im)
feature = zeros(CC.NumObjects, 1)
for i = 1:CC.NumObjects
[x, y] = ind2sub(Size, CC.PixelIdxList{i})
t = fminsearch(@(t)Loss([x y], t), 0)
[~, width] = Loss([x y], t)
feature(i) = width(1)/width(2)
end
feature = sort(feature, 1, 'descend')
function [Loss, width] = Loss(G, t)
R = rot(t)
G = G*R
width = max(G, [], 1) - min(G, [], 1)
Loss = -width(1)/width(2)
end
end
主程序:
im = imread(图片名称)feature = ff(im)
对于题目中的输入图片,得到的feature是:
分别对应四个区域的长宽比。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)