Can I crop an image without fully loading it into memory?

7

2

I managed to generate a PNG image with a fractal.

The image is 65,536 pixels high and 65,536 pixels wide. It’s too big to be decoded into memory and displayed. It has probably a lot of unused space near the borders and I want to trim it to significantly reduce its area.

I tried GIMP and GraphicsMagick, but GIMP froze my computer and GraphicsMagick failed to allocate enough memory for the image.

I use Linux and I have 16GB of RAM. The compressed image is 6.2MB in size.

Can I trim the borders without loading the image fully into memory?

FWIW, in the end I used my school's server but I still want to know the answer.

matj1

Posted 2019-04-12T22:12:49.027

Reputation: 71

1“It has probably a lot of unused space near the borders and I want to trim it to significantly reduce its area.” How do you know that’s the case? And can you edit your question to provide the actual storage size of the image? Like how many MB (or GB) is it? – JakeGould – 2019-04-12T22:37:45.427

I know that because I ran the program to generate the fractal in different sizes. The resolution of the image is based on the number of iterations given as input and it's as small as possible while including the whole fractal and being easily calculatable. – matj1 – 2019-04-12T23:18:15.590

Maybe this could work? https://stackoverflow.com/q/1905421/1922095

– Brian Z – 2019-04-13T17:02:50.177

Why not splitting and conquerring. Divide the image in 3x3 and process the borders then merge back to one. ImageMagick should do – splaisan – 2019-04-13T17:32:07.317

Answers

0

You already know the cartesian definition of the image.

Consider some Python code to read the file in reasonably-sized buffer-loads - choose one or multiple lines of image pixels per buffer, but sufficiently few with regard to memory-availability.

On most pixel-lines, the left-most and right-most "border" pixels can be discarded. The first few, and last few, "border" lines, similarly.

The buffer-size of the output file can, and will, be different to that of the input file, by definition.

d-n

Posted 2019-04-12T22:12:49.027

Reputation: 1