Search code examples
matlabtifflibtiff

Remove Page From Multipage TIFFs In Matlab


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?


Solution

  • 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