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

2 次查看(过去 30 天)
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?

采纳的回答

David Young
David Young 2014-9-16
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 个评论
Image Analyst
Image Analyst 2014-9-16
编辑:Image Analyst 2014-9-16
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by