How to split a large tiff image
7 views (last 30 days)
Show older comments
I have a large tiff image (About 36.9GB), I want to split it to small tiff images,
I have this code,
% Created by Weizhen Fang
clc;
clear;
%input
filepath='O:\fwz\beijing_haidian\haidian.tif';
OutputPath ='O:\fwz\beijing_haidian\split\';
outputname='split_haidian';
cutblocksize=[1024 1024];
info = geotiffinfo(filepath);
fun = @(block_struct)yourAlgorithm(block_struct,OutputPath,outputname,info);
%blockproc(filepath,cutblocksize, fun,'UseParallel',true);
blockproc(filepath,cutblocksize, fun);
function data=yourAlgorithm(blockStruct,OutputPath,outputname,info)
%do your processing of the block here and
data = blockStruct.data;
location= blockStruct.location;
blockSize=blockStruct.blockSize;
SpatialRef_new=info.SpatialRef;
LatitudeLimits=SpatialRef_new.LatitudeLimits;
LongitudeLimits=SpatialRef_new.LongitudeLimits;
CellExtentInLatitude=SpatialRef_new.CellExtentInLatitude;
CellExtentInLongitude=SpatialRef_new.CellExtentInLongitude;
row=location(1,1);
col=location(1,2);
a(1,1)=row+blockSize(1,1);
a(1,2)=row;
a(1,3)=col+blockSize(1,2);
a(1,4)=col;
file_path=[OutputPath,outputname,'_',num2str(row),'_',num2str(col), '.tif'];
img_i_size=blockSize;
SpatialRef_new.RasterSize=img_i_size;
SpatialRef_new.LatitudeLimits(1)=LatitudeLimits(2)-(a(1,1)-1).*CellExtentInLatitude;
SpatialRef_new.LatitudeLimits(2)=LatitudeLimits(2)-(a(1,2)-1).*CellExtentInLatitude;
SpatialRef_new.LongitudeLimits(2)=LongitudeLimits(1)+(a(1,3)-1).*CellExtentInLongitude;
SpatialRef_new.LongitudeLimits(1)=LongitudeLimits(1)+(a(1,4)-1).*CellExtentInLongitude;
geotiffwrite(file_path,data,SpatialRef_new,...
'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag,'TiffType','bigtiff');
end
It is useful when the image is not very large
But when I use it to split the large tiff image (About 36.9GB), the error happened,
Error using repmat
Requested 102241x129113x3 (36.9GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and
cause MATLAB to become unresponsive. See array size limit or preference panel for more information.
Error in blockproc>createOutputAdapter (line 681)
dest_matrix = repmat(outputClass(0),final_size);
Error in blockproc (line 326)
dest = createOutputAdapter(source,...
Error in cut_bigtiff2 (line 23)
blockproc(filepath,cutblocksize, fun);
How to sovle this problems?
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!