Spliting colour channels in multipage TIFF file

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 comentarios

Andrew Chen
Andrew Chen el 26 de Oct. de 2017
Hello Katarzyna, what exactly is the output when you run that first script? Does the script run through to the end or is redchtiff not even being created?
Could it be that the rgbimage variable has 3 dimensions and you're trying to create a 4 dimensional matrix (redChannel) out of it?
I have error here:
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in splitred (line 12)
rgbImage(k,:,:) = imread(original,k);
I don't know how to read multipage tiff correctly and work on all its dimensions after. I am sure that I have stacks of 141 images. They are read by second part of the shorter script correctly.
Andrew Chen
Andrew Chen el 26 de Oct. de 2017
Editada: Andrew Chen el 26 de Oct. de 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!
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.)

Iniciar sesión para comentar.

Respuestas (1)

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 26 de Oct. de 2017

Comentada:

el 27 de Oct. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by