Which color map is returned in example script cam.py ? #312
-
In the example file with cam_algorithm (model = model,
target_layers = target_layers,
use_cuda = args.use_cuda) as cam:
# AblationCAM and ScoreCAM have batch implementations.
# You can override the internal batch size for faster calculation.
cam.batch_size = 32
grayscale_cam = cam (input_tensor = input_tensor,
goals = goals,
aug_smooth = args.aug_smooth,
eigen_smooth = args.eigen_smooth)
# Here grayscale_cam has only one image in the batch
grayscale_cam = grayscale_cam [0,:]
cam_image = show_cam_on_image (rgb_img, grayscale_cam, use_rgb = True)
# cam_image is RGB encoded while "cv2.imwrite" requires BGR encoding.
cam_image = cv2.cvtColor (cam_image, cv2.COLOR_RGB2BGR) My question was about the format of the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
And for example if i try to use an adaptiveThreshold like this: img_thresh_adp = cv2.adaptiveThreshold(grayscale_cam, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 13, 7) i occur this error ---------------------------------------------------------------------------
error Traceback (most recent call last)
[<ipython-input-10-eb93012ef834>](https://localhost:8080/#) in <module>
6
7 # Perform adaptive thresholding.
----> 8 img_thresh_adp = cv2.adaptiveThreshold(grayscale_cam, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 13, 7)
9
10 # Display the images.
error: OpenCV(4.6.0) /io/opencv/modules/imgproc/src/thresh.cpp:1674: error: (-215:Assertion failed) src.type() == CV_8UC1 in function 'adaptiveThreshold' There is some error in the type of grayscale_cam and i don't know what. cv2.imwrite('Mask.png', img_thresh);
mask = cv2.imread("Mask.png", cv2.IMREAD_GRAYSCALE) Can anyone help me? I think it's not the best way to save and reload the image. |
Beta Was this translation helpful? Give feedback.
-
grayscale_cam is a float32 image with values in the range [0, 1]. |
Beta Was this translation helpful? Give feedback.
grayscale_cam is a float32 image with values in the range [0, 1].
Just convert it to np.uint8:
grayscale_cam_uint8 = np.uint8(grayscale_cam * 255)
and save grayscale_cam.