Determining the max angle from the cell array

3 次查看(过去 30 天)
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
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 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by