How to extract RGB matrices from stacked TIFF file?

7 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Aug 2020
Edited: Walter Roberson on 13 Aug 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.

Sign in to comment.

More Answers (1)

hosein Javan
hosein Javan on 13 Aug 2020
Edited: hosein Javan on 13 Aug 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)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!