How to extract RGB matrices from stacked TIFF file?

2 ビュー (過去 30 日間)
iontrap
iontrap 2020 年 8 月 13 日
コメント済み: hosein Javan 2020 年 8 月 14 日
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

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 13 日
編集済み: Walter Roberson 2020 年 8 月 13 日
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 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 14 日
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.
iontrap
iontrap 2020 年 8 月 14 日
Much appreciated, Walter.

サインインしてコメントする。

その他の回答 (1 件)

hosein Javan
hosein Javan 2020 年 8 月 13 日
編集済み: hosein Javan 2020 年 8 月 13 日
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 件のコメント
iontrap
iontrap 2020 年 8 月 14 日
Thanks Hosein. Walter's answer above worked well.
hosein Javan
hosein Javan 2020 年 8 月 14 日
you're welcome, good luck.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by