I have a method in my project in which I verify if a pixel has the desired reliability (in terms of its classification as edge or not) and I plot the pixels in the following scheme:
White -> pixel doesn't have the required reliability
Blue -> pixel has the required reliability and it was classified as not edge
Red -> pixel has the required reliability and it was classified as an edge
This is my code:
def generate_data_reliability(classification_mean, data_uncertainty, x_axis_label, y_axis_label, plot_title,
file_path, reliability):
"""
:classification_mean : given a set of images, how was the mean classification for each pixel
:param data_uncertainty : the uncertainty about the classification
:param x_axis_label : the x axis label of the data
:param y_axis_label : the y axis label of the data
:param plot_title : the title of the data
:param file_path : the name of the file
"""
plt.figure()
# 0 -> certainty
# 1 -> uncertainty
r = 0
b = 0
w = 0
has_reliability = numpy.zeros((data_uncertainty.rows, data_uncertainty.cols), float)
for x, y in product(range(data_uncertainty.rows), range(data_uncertainty.cols)):
# I the uncertainty is > then the required reliability, doesn't show it
if data_uncertainty.data[x][y] > (1.0 - reliability):
has_reliability[x][y] = 0.5
w += 1
else:
has_reliability[x][y] = classification_mean.data[x][y]
if has_reliability[x][y] == 1.0:
r += 1
if has_reliability[x][y] == 0.0:
b += 1
print reliability, w+r+b, w, r, b
plt.title(plot_title)
plt.imshow(has_reliability, extent=[0, classification_mean.cols, classification_mean.rows, 0], cmap='bwr')
plt.xlabel(x_axis_label)
plt.ylabel(y_axis_label)
plt.savefig(file_path + '.png')
plt.close()
And this is the print that I got:
>>>> Prewitt
0.8 95100 10329 0 84771
0.9 95100 12380 0 82720
0.99 95100 18577 0 76523
As can be seen, as the required reliability get higher, less pixels have this reliability (more of then will be plot white and none of them are red).
But this is the plots that I get:
I don't know why, if I have less pixels with the desired reliability, I don't get more white pixels, but these red ones. I'm not changing my objects, to mess with them. Oo
I'm stucked in this problem at about 3 hours with no clue about what is wrong.
EDIT:
In this cmap 0 is blue, 0.5 is white and 1 is red, isn't it? I'm pretty sure that the problem is 'cause I am using a diverging color map and sometimes and don't have a central value. E.g., in the situation that I posted here, I don't have red values, so my values vary between 0.5 and 1. Then, matplotlib automatically set my min value to be red and my max value to be blue. But how could I do that? I choose this 'cause would like to represent colors in the scheme: 0=blue, 0.5=white and 1=red (My values will always be 0, 0.5 or 1).
Any help would be very, very much appreciated.
Thank you in advance.