I was following the post:

Display grayscale image as 3d plot

But the method failed for any image of substantial size (in my case when the data size is of order 3072x4096). Ram usage on my machine jumps to maximum and then the kernel aborts. On a more powerful machine, it completely froze my system.

My guess is I either have to create an interpolation, down-sample somehow, or modify the settings of ListPlot3D.

The code I used is:

complexImage = Import["somePath"]
data = Reverse[ImageData[RemoveAlphaChannel[ColorConvert[complexImage, "Grayscale"]]]]
ListPlot3D[data,AxesLabel -> {"x", "y", "z"}]

The dimensions of data are {3072,4096}. I'm not too familiar with Mathematicas image processing techniques so any assistance would be appreciated.


1 Answer 1


Well, 12 million data points is a lot for the plotting algorithm to handle. If you have enough RAM, it should return a result eventually, but it would probably take a long time and use a ton of RAM. I tried it with a 15MP image, and my RAM usage shot up before levelling off. I got tired of waiting for it to complete, though.

If you're okay with resampling the image, I would use:

complexImage = ImageResize[Import["somePath"], 1600]
data = Reverse[ImageData[RemoveAlphaChannel[ColorConvert[complexImage, "Grayscale"]]]]
ListPlot3D[data, AxesLabel -> {"x", "y", "z"}]

where the 1600 is some reasonable size. If you look up Resampling in the documentation, you can also control exactly how the image is resampled. If you don't particularly care how the image is sampled, you could also do:

ListPlot3D[data[[;; ;; n, ;; ;; n]], ...]

where it will take every $n^{th}$ data point, or

ListPlot3D[Downsample[data, n], ...]

which has the same effect. On my computer it took about 38 seconds to return the ListPlot3D for a 1600 x 1067 image.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.