Determining the max angle from the cell array

2 ビュー (過去 30 日間)
prashanth A
prashanth A 2018 年 8 月 29 日
編集済み: dpb 2018 年 8 月 29 日
I have a 1x3 cell array, where each layer is 512 x 512, returned by a function. I want to scan through the cell at every pixel and determine the maximum angle. The code that I have written is working fine, but I feel that it can be made more simple by using the features of cell.
Also if the cell dimensions change, say from 1x3 to 1x5 then this code has to be reworked. Please suggest the necessary changes.
max_edges_anglesR = zeros(size(R_portion)); % Creating a matrix to hold maximum values
C1 = Ang_F1{1,1}; % Ang_F1 is the array, and one layer is assigned to C1, C2 etc
C2 = Ang_F1{1,2};
C3 = Ang_F1{1,3};
for i=1:1:size(C1,1)
for j=1:1:size(C1,2)
C1_angle = angle(C1(i,j)); % for a given (i,j), temporarily store
C2_angle = angle(C2(i,j));
C3_angle = angle(C3(i,j));
max_angle = max([C1_angle, C2_angle, C3_angle]); % Find the max
max_edges_anglesR(i,j) = max_angle;
end
end
imshow(max_edges_anglesR); title('Max angles'); figure

採用された回答

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2018 年 8 月 29 日
編集済み: Kaushik Lakshminarasimhan 2018 年 8 月 29 日
This should do. Change ncells as desired.
ncells = length(Ang_F1);
max_edges_anglesR = max(angle(reshape(cell2mat(Ang_F1),[512 512 ncells])),[],3);

その他の回答 (1 件)

dpb
dpb 2018 年 8 月 29 日
編集済み: dpb 2018 年 8 月 29 日
A cell array just gets in the way here. I'd look back at how the Ang_F1 is generated and see if can't just get the array directly.
But, for your particular code snippet, just convert to an array (which since Ang_F1 is 1x3 will catenate the three horizontally), reshape() it by the size of one cell array by 3 planes to 3D array and take the max() along the third dimension.
max_angle= max(reshape(cell2mat(Ang_F1),[size(Ang_F1{1}),3]),[],3);

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by