Spliting colour channels in multipage TIFF file
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Andrew Chen
2017-10-26
编辑:Andrew Chen
2017-10-26
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!
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!