Effacer les filtres
Effacer les filtres

Determining the max angle from the cell array

1 vue (au cours des 30 derniers jours)
prashanth A
prashanth A le 29 Août 2018
Modifié(e) : dpb le 29 Août 2018
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

Réponse acceptée

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan le 29 Août 2018
Modifié(e) : Kaushik Lakshminarasimhan le 29 Août 2018
This should do. Change ncells as desired.
ncells = length(Ang_F1);
max_edges_anglesR = max(angle(reshape(cell2mat(Ang_F1),[512 512 ncells])),[],3);

Plus de réponses (1)

dpb
dpb le 29 Août 2018
Modifié(e) : dpb le 29 Août 2018
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);

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by