Issue
I don't know why the graph is turned.
Here is my code:
import matplotlib.pyplot as plt
import numpy as np
img = plt.imread('tree.png')
img = img[:,:,0]
img = -img + 1
points_in = [[],[]]
points_out = [[],[]]
n = 100000
x = np.random.randint(img.shape[0],size = n)
y = np.random.randint(img.shape[1], size = n)
hit = 0
for i in range(n):
if img[x[i],y[i]] != 0:
points_in[0].append(x[i])
points_in[1].append(y[i])
hit += 1
else:
points_out[0].append(x[i])
points_out[1].append(y[i])
square = img.shape[0] * img.shape[1]
hit_rate = hit / n
result = square*hit/n
print(square, hit,hit_rate, result)
img = -img + 1
plt.imshow(img,cmap='gray')
plt.scatter(points_in[0],points_in[1],c='b',s=0.1)
plt.scatter(points_out[0],points_out[1],c='r',s=0.1)
plt.show()
I think a index of the list doesn't look like a problem. I want to know why the graph is turned.
Solution
I think you mixed up x and y coordinates:
1st index of img should be y, 2nd coordinate is x.
But you are using img[x[i],y[i]]
.
Answered By - thmint
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.