用python提取图片主要颜色,在Python中从图像中提取特定颜色范围的简单方法?

使用cv2模块从图像中提取特定RGB范围(黄色到白色)的颜色,并计算该范围内像素的比例。代码示例中,尝试从航天飞机尾气图片中隔离火光,但结果显示0%像素在指定范围内。
摘要由CSDN通过智能技术生成

I'm trying to extract a specific color from an image within a defined RGB range using the cv2 module. In the example below I am trying to isolate the fire from the exhaust of the space shuttle between yellow and white RGB values and then print out the percentage of RGB values within that range compared to the rest of the image.

Here is my minimal working example:

import cv2

import numpy as np

from matplotlib import pyplot as plt

import imageio

img = imageio.imread(r"shuttle.jpg")

plt.imshow(img)

This is the output image. Its from wikipedia.

58b5ecbc6c00d689206f011b1a4e6377.png

img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

color1 = (255,255,0) #yellow

color2 = (255,25

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值