I have tiff files where I want to remove the even numbered pages. I have read other posts asking for the method in many different languages except for Matlab. How can this be done in Matlab?
Asked
Active
Viewed 120 times
0
-
1Too broad. Just look at the docs for [reading a page](http://www.mathworks.com/help/matlab/ref/imread.html#inputarg_idx) and [writing multiple pages](http://www.mathworks.com/help/matlab/ref/imwrite.html#input_argument_namevalue_writemode) – Suever Jun 14 '16 at 16:22
-
I did take a look at them but didn't find what I was looking for. – Senyokbalgul Jun 15 '16 at 12:38
1 Answers
1
The solution for your problem is to read only the relevant tiff pages (i.e. the odd ones) and the save them in a separate file. This can be done as follows:
%defines path to input and output files
inputFileName = '<input file name>';
outFileName = 'out.tiff';
%reads tiff file info
tiffData= imfinfo(inputFileName);
%reads every odd page and append it to the output file
for k = 1:2:numel(tiffData)
currentTiff = imread(inputFileName,k);
imwrite(currentTiff, outFileName, 'writemode', 'append');
end

ibezito
- 5,782
- 2
- 22
- 46
-
-
-
@Suever Actually the code above saved it, thanks though. Although, is there a way to save the output file to a different folder than the input folder? – Senyokbalgul Jun 15 '16 at 12:42
-
Sure, use the full path for the output file name. For example, if you want the output file to be located at C:\newDirectory, simply write: outFileName = 'C:\newDirectory\out.tiff'; – ibezito Jun 15 '16 at 13:06
-