The pred variable is a single-channel density map of the network output. Density maps need to be converted to the CPU-supported NUMPY format when they are drawn.

1. Draw with PIL

import matplotlib.pyplot as plt
plt.imshow(pred, cmap=plt.cm.jet)
plt.show()

This rendering method will have its own coordinate system, and this coordinate system will occupy the real pixel points of the image, resulting in the size of the output density map is not consistent with the size of the input image. However, if you are just looking at the density effect, this method is recommended.

2. Use CV2 to draw

import cv2
heatmapshow = None
heatmapshow = cv2.normalize(pred, heatmapshow, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
heatmapshow = cv2.applyColorMap(heatmapshow, cv2.COLORMAP_JET)
cv2.imshow("Heatmap", heatmapshow)
cv2.waitKey(0)

We know that the values in the pred matrix output from the network are all very small and are the floating point numbers of np.float64, while CV2 deals with the numbers in the range [0,255], so if you display or save them directly with CV2, it will be a dark picture.

PLT. IMShow is actually a normalized operation of pred and then color mapping is applied to present the effect of heat map. So in CV2, you need to do the same two steps: The cmap parameters in plt.imShow are equivalent to the cv2.colormap_jet parameters in cv2.applycolormap, which are used to specify colors.


Reference:


https://blog.csdn.net/hxydip/…