Spliting colour channels in multipage TIFF file

1 visualizzazione (ultimi 30 giorni)
I know how to split channels and save extracted data when an input is a single image. https://www.mathworks.com/matlabcentral/answers/91036-split-an-color-image-to-its-3-rgb-channels ?
I don't know how to modify the code to extract only red channel from multipage TIFF and save it as another multipage TIFF. I am aware that dimensions are defined in wrong way but after multiple trials I don't know how to do it correctly. Please help me.
function [redchtiff] = splitred(original)
% Read in original RGB image.
info1 = imfinfo (original);
h = max([info1.Height]);
w = max([info1.Width]);
l = length([info1.FileSize]);
rgbImage = zeros(h,w,l);
for k = 1:l
rgbImage(:,:,k) = imread(original,k);
end
% Create an all black channel.
allBlack = zeros(size(rgbImage, 1), size(rgbImage, 2), 'uint8');
% Extract red channel.
redChannel = rgbImage(:,:,1,:);
% Create color version of the red channels.
redch = cat(3, redChannel, allBlack, allBlack);
filename =[original(1:size(original,2)-4),'red.tif'];
redchtiff = imwrite(redch(:,:,:), filename);
end
This function is called by the script which after analyses only red images calling another function:
folder = '...';
orgtifFiles = dir([folder filesep '*tif']);
for iFile = 1: numel(orgtifFiles)
splitred(orgtifFiles(iFile).name);
end
redtifFiles = dir([folder filesep '*red.tif']);
for iFile = 1: numel(redtifFiles)
acridineorange(redtifFiles(iFile).name)
end
  4 Commenti
Andrew Chen
Andrew Chen il 26 Ott 2017
Modificato: Andrew Chen il 26 Ott 2017
I see. So with rgbImage you're trying to create an mxnx141 matrix (since you have 141 images or frames).
rgbImage = imread(original);
should do what you need, you should not need the for loop. imread should create that mxnx141 matrix. you may run into errors later in the code...
If you could attach one of the the multi page tiff's you're trying to read, I'd be happy to run and troubleshoot your code within the next 12 hours!
Katarzyna Wieciorek
Katarzyna Wieciorek il 27 Ott 2017
File is too big to attach, use this link: sample multipage TIFF
Can you help me add a line with autothreshold basing on the last frame after spliting but before running the shorter script with another function? (Autothreshold is supposed to eliminate the backgrond.)

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 26 Ott 2017
rgbImage(:,:,:,k) = imread(original,k);

Community Treasure Hunt

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

Start Hunting!

Translated by