How to extract RGB matrices from stacked TIFF file?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
iontrap
le 13 Août 2020
Commenté : hosein Javan
le 14 Août 2020
I have a (512x512x3xN) image array where 3 corresponds to the R,G,B channels, and N corresponds to the number of images. How can I extract the R,G,B channels from each image?
I will eventually want to compute mean and stdev for each R,G,B channel of each of the N images and put these into a txt file.
Thanks
0 commentaires
Réponse acceptée
Walter Roberson
le 13 Août 2020
Modifié(e) : Walter Roberson
le 13 Août 2020
squeeze(mean(YourArray, [1 2]))
squeeze(std(YourArray, [], [1 2]))
These should give you a 3 x N array of values that are the means or std over each color plane in each image . There is no need to extract each color plane individually.
If your MATLAB is too old to support multiple dimensions, then you can always do
squeeze( mean(reshape(YourArray, [], 3, size(YourArray,4))) )
squeeze( std(reshape(YourArray, [], 3, size(YourArray,4))) )
This reshapes each color plane of each image into a single column and processes each column.
3 commentaires
Walter Roberson
le 14 Août 2020
N = 5;
YourArray = randi([0 255], 512, 512, 3, N, 'uint8');
squeeze(mean(YourArray, [1 2]))
squeeze(std(double(YourArray), [], [1 2]))
ans =
127.132061004639 127.566165924072 127.579082489014 127.507698059082 127.727783203125
127.585601806641 127.300945281982 127.553031921387 127.218353271484 127.638935089111
127.607196807861 127.465267181396 127.508388519287 127.246562957764 127.548515319824
ans =
73.8924076662466 73.8391486006418 73.8645348408521 73.9474347695904 73.833758311485
73.9576801440049 73.9752296400623 73.9673059233171 73.8467401920338 73.8984297781487
73.8960669386365 73.9675846490088 73.7850595136846 73.8375167219068 73.986046349694
So that is 3 x 5 output arrays when there were 5 panes.
... In other words the code already does what you are asking for.
Plus de réponses (1)
hosein Javan
le 13 Août 2020
Modifié(e) : hosein Javan
le 13 Août 2020
not sure.
% A = your matrix after reading the image file
im = cell(1,n);
for i = 1:N
im{i} = A(:,:,:,i) % im{i} = individual image number(i)
end
6 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!