1

I have a monochrome image whose size is greater than 10 gigabytes (50000x50000). This image has a lot of "holes", pixels with NULL value.

Conventionally, I know how to use python griddata function to read in the whole image and fill the pixels with NULL value with different interpolation method. But the problem now is that I can't process the whole image at once due to the size of this image, which will give me an memory exhausted error.

So, now my idea is that I could divide this image into 2500 (50x50) windows and I run the interpolation method on each window. But the obvious problem is that for each window, the NULL pixel is interpolated with neighboring pixels only in the same window, which is against the nature of an image, because the pixel on the edge of a window can not be interpolated by the pixel in neighboring windows. In order to solve this problem, overlapping the windows may be a solution. I can only think of this solution. Does anyone know if there is an efficient and intact method to interpolate a very large image.

Lion Lai
  • 1,862
  • 2
  • 20
  • 41
  • 1
    Overlapping windows seems the right approach to me. The size of the overlap would depend on how far apart the values to interpolate are, which depends on the fraction of pixels with a NULL value. – Cris Luengo Apr 27 '20 at 15:13
  • 1
    Don't commit, too soon, to using square windows. For such a large image you might get better performance from `10x50000` windows (replace `10` by whatever is large enough for the interpolation you choose) than from square windows with the same number of pixels. – High Performance Mark Apr 27 '20 at 15:17
  • 1
    Probably using `vips` which is very good at this sort of thing. It may help if you add that tag and give details of what programming language and operating system you have available and also some indication of the format the data are currently stored in. – Mark Setchell Apr 27 '20 at 16:54
  • From your sizings, I am assuming your data is 32-bit floats - correct? Whilst I suspect `vips` would be a better tool, if you are really stuck, you may find that you can use **ImageMagick** `stream` tool to extract overlapping chunks of an image for further processing... https://imagemagick.org/script/stream.php – Mark Setchell Apr 29 '20 at 08:06

1 Answers1

1

You'd need to give a lot more information I think, but if the holes are small, one simple solution is just to replace null pixels with values from a median filter.

For example, using pyvips:

#!/usr/bin/python3

import sys
import pyvips

image = pyvips.Image.new_from_file(sys.argv[1], access="sequential")
image = (image == 0).ifthenelse(image.median(5), image)
image.write_to_file(sys.argv[2])

That will open the image in sequential mode (we only need to make one pass over the image, so we don't need random access to pixels). A 5x5 median filter can fill holes up to perhaps three pixels across. You can use a larger window to fill larger holes, but of course it'll get slower.

It should be pretty quick, and it'll work on images of any size using only a little memory.

You'd need to consider something more complex if you need to fill large areas.

jcupitt
  • 10,213
  • 2
  • 23
  • 39