Discussion:
[Matplotlib-users] imshow() and pixel intensity
Amit Saha
2015-05-17 12:02:35 UTC
Permalink
Hi all,

Just trying to understand how the value of the matrix fed to imshow()
function determines the intensity of the pixel in grey scale mode.
Consider the example code:

import random
import matplotlib.pyplot as plt
import matplotlib.cm as cm

def pixels(n=3):
pixel_data = []
for _ in range(n):
row = []
for _ in range(n):
row.append(random.randint(1, 10))
pixel_data.append(row)
return pixel_data

if __name__ == '__main__':
pixel_data = pixels()
print(pixel_data)
plt.imshow(pixel_data, origin='lower', cmap=cm.Greys_r)
plt.show()


The pixel_data here is the 3*3 "matrix":
[[7, 4, 6], [7, 7, 6], [4, 7, 9]]

How does the values here determine what shade of grey I see in the image?

Thank you in advance.

Best,
Amit.
--
http://echorand.me
Amit Saha
2015-05-18 12:31:12 UTC
Permalink
Got my answer here:
http://stackoverflow.com/questions/30301986/matplotlib-imshow-and-pixel-intensity
Post by Amit Saha
Hi all,
Just trying to understand how the value of the matrix fed to imshow()
function determines the intensity of the pixel in grey scale mode.
import random
import matplotlib.pyplot as plt
import matplotlib.cm as cm
pixel_data = []
row = []
row.append(random.randint(1, 10))
pixel_data.append(row)
return pixel_data
pixel_data = pixels()
print(pixel_data)
plt.imshow(pixel_data, origin='lower', cmap=cm.Greys_r)
plt.show()
[[7, 4, 6], [7, 7, 6], [4, 7, 9]]
How does the values here determine what shade of grey I see in the image?
Thank you in advance.
Best,
Amit.
--
http://echorand.me
--
http://echorand.me
Loading...