Crop Large TIFF Image.NET without reading image into memory

I am trying to find a way to crop large TIFF images in .NET. In particular, I am trying to perform this operation on GeoTiff, TIFF, which allows you to embed geo-referencing information. For those who are not familiar with this type of dataset, it is fully compatible with TIFF 6.0 and usually has a huge size; many times in the gigabyte range.

I tried with the System.Windows.Media.Imaging namespace to try to complete this task. However, the size of the trimmed tiff causes errors in memory. Can someone please give me some information showing how to crop an image without reading the input image into memory at the beginning?

FYI - I fully understand that GDAL is more than capable of this task. However, without going into unnecessary details, deploying GDAL with my application is currently not an option for several reasons, so my desire is to do this using my own .NET classes. However, if there are other third-party .NET libraries that might be useful, I'm all ears.

+4
source share
3 answers

Take a look at libtiff . You want to load an image by scan lines (or stripes, if that is how the image is formatted). Obviously, you still need enough memory to hold the entire line (or strip), but this is more possible than loading the entire image into memory.

There seems to be a .NET version of the library , and it looks like free and open source (unlike some other applications).

+3
source

Unfortunately, the built-in GDI + -based image processing operations (available within System.Drawing and System.Drawing.Imaging ) require that the full image be loaded into memory at some point. This is clearly not possible in your situation.

+1
source

You should not consider TIFF in the gigabyte range as an “image”: consider it as a file on disk or display it in memory and perform operations on it as if it were a data set.

The image namespace is not designed for such large data sets, it is designed to work with images, smaller images, etc. You will either have to find the TIFF manipulation library or write your own routines for working at the file level. There is an open source C library called "libtiff" that I have worked with in the past; this could be a good starting point.

(Some of the difficulties you will have to deal with include the fact that TIFF files can have all kinds of compression - if it's geotechnical, is there probably standard / direct compression or is it uncompressed? In this case, copying the memory around will be the most work and save TIFF directories and records. I would suggest looking at the Atalasoft DotImage library if you are after a commercial version.)

+1
source

Source: https://habr.com/ru/post/1339233/


All Articles