2

I am trying to display a sentinel-1 satellite image which is of size 26000(width) X 17000(height) pixels and using Python 3.5. I am able to load this image in numpy as an array and trying to display in matplotlib but unable to do as it gives Memory Error..The screen resolution is 1600(width) X 1200(height) pixels.I am using windows 7 with 8GB RAM. I agree that it might not be able to display due to memory constraints but is there any way I can display such huge image ? Also I have seen many satellite image processing softwares such as SNAP(sentinel toolbox) which can display such huge images in the above specified screen resolution, but cannot find how they do it. Kindly help.

6
  • The question is a bit, what do you need such large image for inside a matplotlib plot. If it is for showing on screen, it would probably not make sense to show a 26000 pixel image on a 2000 pixel screen as only every 13th pixel can be displayed anyways. Commented Sep 24, 2018 at 12:28
  • @ ImportanceOfBeingErnest : Is there anyway to do scaling, as I have seen in Sentinel-1 toolbox (SNAP),the whole image can be displayed in it even if it does not match the screen resolution.But wonder how does it do? Commented Sep 24, 2018 at 18:48
  • Matplot will automatically scale the image to fit into the axes. My point was that you do not need to supply 13*13=169 color values for a single pixel on screen. Commented Sep 24, 2018 at 18:50
  • @ ImportanceOfBeingErnest : I just want to display a grayscale image...maybe any way out according to you. Commented Sep 24, 2018 at 18:53
  • Reduce the 26000x17000 array to a 2000x1307 array. Plot that reduced array. Commented Sep 24, 2018 at 18:55

1 Answer 1

0

Tried to create an image with the width and height as specified by you. My screen resolution is 1920 by 1080, FHD

import matplotlib
matplotlib.rcParams['figure.dpi'] = 120
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from numpy.random import randn
fig, ax = plt.subplots()
data = np.clip(randn(26000, 17000), -1, 1)
cax = ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm)

cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
cbar.ax.set_yticklabels(['< -1', '0', '> 1'])  

plt.show()

The plot is generated but about 7GB of memory is eaten by python!

enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

I suppose by "image" the OP means something like rand(17000,26000,3), which would sure use a lot more memory.
@Khalil Al Hooti I tried your code brother but still there is the same Memory Error. I am unable to display even your image . Kindly suggest any better option.
@Shubham_geo I suggest you decrease the data volume by taking every 3rd or 4th value in each direction. for example in the code above you could try to do data = data[::3, ::3], and take @ImportanceOfBeingErnest suggestion into consideration. The plot will will not be generated as it is since the numpy 2d array is taking huge chunk of memory beyond the ram your computer has! my pc has 32 gb of ram

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.