2

I am currently trying to visualize three 2D arrays with the same color. The arrays are 13x13 and contain integers. In an external file I have a color code in hex for each integer.

When I now try to visualize the arrays, two out of three arrays look good. All numbers match the color codes and display the arrays correctly. But in the last picture a part of the data is not assigned correctly.

Here is a picture of my problem.

color_names = [c.strip() for c in open(colors).readlines()]
color_dict =  {v: k for v, k in enumerate(color_names)}

unique_classes = (np.unique(np.asarray(feature_map))).tolist()
number_classes = len(unique_classes)

color_code = [color_dict.get(cla) for cla in unique_classes]


cmap = plt.colors.ListedColormap(color_code)
norm = plt.colors.BoundaryNorm(unique_classes, cmap.N)

img = pyplot.imshow(feature_map[0],interpolation='nearest',
cmap = cmap,norm=norm)

pyplot.colorbar(img,cmap=cmap,
norm=norm,boundaries=unique_classes)
pyplot.show()

img1 = pyplot.imshow(feature_map[1],interpolation='nearest',
cmap = cmap,norm=norm)
pyplot.show()

img2 = pyplot.imshow(feature_map[2],interpolation='nearest',
cmap = cmap,norm=norm)

pyplot.colorbar(img2,cmap=cmap,
norm=norm,boundaries=unique_classes)

pyplot.show()

Exactly the same data as on the picture:

feature_map = [[[25,25,25,25,56,56,2,2,2,2,2,2,25],[25,25,25,25,25,25,59,7,72,72,72,72,2],[25,25,25,25,25,25,59,72,72,72,72,72,2],[25,25,25,24,24,24,62,0,0,0,0,25,25],[25,25,24,24,24,24,24,24,24,24,25,25,25],[26,26,24,24,24,24,24,26,26,26,6,6,6],[26,26,26,24,24,26,26,26,26,26,26,6,6],[26,26,26,0,0,26,26,26,26,26,26,6,6],[28,28,28,28,28,28,28,26,26,26,26,6,6],[28,28,28,28,28,28,28,26,26,26,13,13,6],[28,28,28,28,28,28,28,26,13,13,13,13,13],[28,28,28,28,28,28,28,13,13,13,13,13,13],[28,28,28,28,28,28,28,13,13,13,13,13,13]],[[25,25,25,25,59,56,59,2,0,0,0,0,0],[25,25,25,25,25,59,59,7,72,72,72,72,72],[25,25,25,25,25,25,59,72,72,72,72,72,72],[25,25,25,0,0,25,25,6,0,0,0,72,0],[25,25,0,0,0,0,6,0,0,0,0,25,6],[26,26,26,0,0,0,24,26,0,0,6,6,6],[26,26,26,0,0,0,26,26,26,26,26,6,6],[0,26,0,0,0,0,26,26,0,26,26,6,6],[0,28,28,28,28,28,28,26,0,26,26,6,6],[28,28,28,28,28,28,28,26,0,26,0,0,0],[28,28,28,28,28,28,28,26,13,13,13,13,0],[56,56,28,28,28,28,28,13,13,13,13,13,13]],[[0,28,28,28,28,28,28,13,13,13,13,13,0],[25,25,25,25,59,59,59,4,0,0,0,0,0],[25,25,25,25,59,59,59,7,7,7,72,72,6],[25,25,25,25,25,25,59,7,7,73,73,25,0],[25,25,25,0,0,25,6,7,0,6,6,6,0],[25,0,0,0,6,6,6,6,0,0,6,6,6],[0,0,0,0,0,6,6,6,0,0,6,6,6],[0,0,0,0,0,0,6,6,0,0,6,6,6],[0,0,0,0,0,0,6,0,0,0,6,6,6],[0,0,28,0,28,28,13,0,0,0,6,6,6],[28,28,28,28,28,28,13,13,13,0,13,6,6],[28,28,28,28,28,28,28,13,13,13,13,13,13],[56,28,28,28,28,28,28,13,13,13,13,13,13],[28,28,28,28,28,28,28,13,13,13,13,13,13]]]


The color code file is simply a file where each line contains a single hex code such as: #deb887

I have been working on this problem for several hours and can't reproduce the problem at the moment

1 Answer 1

1

I have tried to reproduce your results and something got my attention.

results reproduced

If you look closely to the feature_map[2] values you might see that the pixel you claim miss classified has actually a different value than the pixels around it. So it actually has the correct color for its value. So I think it is not because of a misclassification it is beacause of your data. That would be my answer IF what you mean by "part of the data" is the pixel at position (0,11) otherwise i have gotten it all wrong and sorry about this answer.

NOTE: About colors, I just picked some random colors. Don't worry if they don't match.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your feedback. I don't mean the one pixel with the number 56 but rather the area around it (the numbers 28). In the first two feature maps the areas with the digits 28 have a purple color whereas in the last feature map the 28 are not purple anymore. I hope I could describe the problem a bit more concretely
It is very odd instead of drawing color assigned to 28 it draws color assingned to 26 which comes right before 28. And if I turn every 28 into the next color value mapped which is 56 they all change to 28's color. So in last image, in that particular lower left corner every mapped pixel value gets colored as if they have the previous pixel value in the cmap order.
Exactly. How is that possible? Is there an automatable solution? The error seems to me to be random, but I cannot correct this manually for all feature maps
I just tried increasing pixel values of false colored pixels by one and it did the trick. But it is really odd. I mean it is almost like a bug of some sort. Because it occurs locally within the image. And the only difference I could find between the feature_maps is the unique pixel value count. I tried changing the data type, increasing the cmap and norm size but no avail.
Maybe you should post it here github.com/matplotlib/matplotlib/issues with detailed explaination and with our findings.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.