異なるセル配列の要素を比較する際に問題が発生しています。
この問題のコンテキストはbwboundaries
、MATLAB の関数を使用して画像の輪郭をトレースしていることです。画像は構造断面であり、断面全体に連続性があるかどうかを確認しようとしています (つまり、bwboundaries
コマンドによって生成されるアウトラインは 1 つだけです)。
これを実行して、トレースされた複数のセクション (つまり、連続していない) を見つけたので、cornermetric
コマンドを使用して各セクションのコーナーを見つけました。
私が持っているコードは次のとおりです。
%% Define the structural section as a binary matrix (Image is an I-section with the web broken)
bw(20:40,50:150) = 1;
bw(160:180,50:150) = 1;
bw(20:60,95:105) = 1;
bw(140:180,95:105) = 1;
Trace = bw;
[B] = bwboundaries(Trace,'noholes'); %Traces the outer boundary of each section
L = length(B); % Finds number of boundaries
if L > 1
disp('Multiple boundaries') % States whether more than one boundary found
end
%% Obtain perimeter coordinates
for k=1:length(B) %For all the boundaries
perim = B{k}; %Obtains perimeter coordinates (as a 2D matrix) from the cell array
end
%% Find the corner positions
C = cornermetric(bw);
Areacorners = find(C == max(max(C))) % Finds the corner coordinates of each boundary
[rowindexcorners,colindexcorners] = ind2sub(size(Newgeometry),Areacorners)
% Convert corner coordinate indexes into subcripts, to give x & y coordinates (i.e. the same format as B gives)
%% Put these corner coordinates into a cell array
Cornerscellarray = cell(length(rowindexcorners),1); % Initialises cell array of zeros
for i =1:numel(rowindexcorners)
Cornerscellarray(i) = {[rowindexcorners(i) colindexcorners(i)]};
%Assigns the corner indicies into the cell array
%This is done so the cell arrays can be compared
end
for k=1:length(B) %For all the boundaries found
perim = B{k}; %Obtains coordinates for each perimeter
Z = perim; % Initialise the matrix containing the perimeter corners
Sectioncellmatrix = cell(length(rowindexcorners),1);
for i =1:length(perim)
Sectioncellmatrix(i) = {[perim(i,1) perim(i,2)]};
end
for i = 1:length(perim)
if Sectioncellmatrix(i) ~= Cornerscellarray
Sectioncellmatrix(i) = [];
%Gets rid of the elements that are not corners, but keeps them associated with the relevent section
end
end
end
これにより、最後の for ループでエラーが発生します。配列の各セル (x 座標と y 座標を含む) がcornercellarrayの座標のペアと等しいかどうかを確認する方法はありますか? マトリックスを使用して、特定の要素が別のマトリックスの要素と一致するかどうかを比較できることを知っています。ここで同じことができるようにしたいのですが、セル配列内の座標のペアに対してです。
cornercellarrayセル配列自体を使用しない理由は、これがすべてのコーナー座標をリストし、それらを特定のトレース境界に関連付けないためです。