Azzera filtri
Azzera filtri

How to store number of images matrix and double values in cell or array?

1 visualizzazione (ultimi 30 giorni)
I am not to familiar with arrays or cells in MATLAB. I would like to make an array that contains in one cell for image 1, image 2, image 3 etc the following per image;
Image Matrix (Pixel value (n x m size) matrix of image) - M
string value - imageType
double value - pos
double value - exposure
How do I do this?
It should be mentioned I will use the values above (matrix and the values) for calculations like sum and so forth etc.
Also, how do I sort them in decreasing order of pos value so that the others also are sorted accordingly?

Risposta accettata

David Young
David Young il 16 Set 2014
Cell arrays could be used, but this looks like an ideal case for a struct array. See this introduction. You might do something like this:
for imageNumber = 1:numberOfImages
<read in or compute the current image and its associated data to the variables
M, imageType, pos and exposure>
imageStruct(imageNumber).imageMatrix = M;
imageStruct(imageNumber).imageType = imageType;
imageStruct(imageNumber).pos = pos;
imageStruct(imageNumber).exposure = exposure;
end
Then to sort, something like this:
[~, sortedIndices] = sort([imageStruct.pos], 2, 'descend');
imageStruct = imageStruct(sortedIndices);
which will keep each image with its associated data in the sorted array.
  1 Commento
Image Analyst
Image Analyst il 16 Set 2014
Modificato: Image Analyst il 16 Set 2014
I agree that a struct array is better and much simpler to understand. That said, the FAQ has a good discussion of cell arrays that should help you get a good intuitive feeling for them http://matlab.wikia.com/wiki/FAQ#Can_you_program_up_the_algorithm_in_this_article_for_me_and_explain_it_to_me.3F>, but again, I recommend David's approach.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by