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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by