Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot log normalized image using imshow () (matplotlib)? [closed]

I understand the concept. But I think I am making a silly mistake. This is what I want (psuedo-ish code). This is for an exercise. I am unable to understand lower origin part and the syntax of the first two lines.

norm = LogNorm(image.mean() + 0.5 * image.std(), image.max(), clip='True', 
               cmap=cm.gray, origin="lower")

image is a numpy array here. How to pass these norm and cmap parameters in matplotlib to plt.show or imshow()?

This doesn't work:

imshow(image, cmap=cm.gray, LogNorm(......))
like image 619
madratman Avatar asked Oct 01 '22 06:10

madratman


1 Answers

Does this work?

from matplotlib import colors, cm, pyplot as plt

norm = colors.LogNorm(image.mean() + 0.5 * image.std(), image.max(), clip='True')
plt.imshow(image, cmap=cm.gray, norm=norm, origin="lower")

This creates a special colormap that ranges from image.mean() + 0.5 * image.std() to image.max() using a logarithmic scale. More general information is here: colors and specifically: LogNorm

The origin='lower' means that the [0,0] element (the 'origin') of the array is shown in the lower left part of the figure. Normally the origin of an array is in the upper left.

like image 197
askewchan Avatar answered Oct 17 '22 17:10

askewchan