How to extract RGB matrices from stacked TIFF file?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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.
更多回答(1 个)
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!