[英]How to save image using opencv after done this code as shown below?
I had use otsu's method for mask the cloud. 我曾经用大津的方法遮盖云。 In this case, the mask is red.
在这种情况下,遮罩是红色的。 When I run the code, the graphs display the red mask but when i try saving it to folder , the mask turn to blue.
当我运行代码时,图形显示红色遮罩,但是当我尝试将其保存到folder时,遮罩变为蓝色。 Can anyone help what I've done wrong?
谁能帮助我做错了事?
def show_mask(mask, img_array, title='', mask_color=(255, 0, 0)):
display_image = img_array.copy()
display_image[mask != 0] = mask_color
path1="D:Datasets/satellite2/croppedred"
plt.imshow(display_image)
cv2.imwrite(os.path.join(path1,img),display_image)
#display_image.save(os.path.join(path1,img))
plt.title(title)
plt.axis('off')
plt.show()
show_mask(mask_otsu_clean, img_array, title='Otsu grayscale thresholding with morphological cleanup')
OpenCV treats the colour channel order of images by default to be BGR and not RGB this is why you see a blue colour mask. OpenCV默认将图像的颜色通道顺序视为BGR而不是RGB,这就是为什么您看到蓝色蒙版的原因。
So you need to change your mask to this 所以你需要换个面具
mask_color = (0, 0, 255)
then it will apply the correct colour values to the correct colour channel 然后它将正确的颜色值应用于正确的颜色通道
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.