如何确定图像是否单色

问题描述 投票:0回答:1

我必须确定图像是否是单色的。我的意思是单色不仅是黑白的。它可能是棕褐色,如红色或蓝色阴影,甚至是混合的红色和蓝色阴影a.s.o(单色缩放)?

我想我们可以说比例尺是从黑色(0,0,0)到白色(255,255,255)的,因为它不是线性的。它是每个颜色通道上的特定曲线

我希望我很清楚:)

谢谢您的帮助

yves

image colors scale
1个回答
0
投票

如果您想到这样的灰度图像:

enter image description here

图像中存在的所有RGB三元组将在连接RGB [0,0,0](即,黑色到RGB [255,255,255],即RGB颜色立方体中的白色)的直线上或附近。

enter image description here

并且所有单色图像都是这种情况-所有RGB三胞胎都将出现在RGB彩色立方体中的一条直线附近。在蓝绿色中,直线将穿过深蓝色和浅蓝色。在棕褐色图像中,直线将穿过棕色和浅棕色,而在红蓝色双色调中,直线将连接RGB立方体内的红色和蓝色点。

让我们看一些图像及其散点图...

灰度

enter image description here enter image description here


cyanotype

enter image description here enter image description here


双色调

enter image description here enter image description here


棕褐色

enter image description here enter image description here


我将数学留给其他人,但是我认为一种可能对您有用的技术是将一条直线拟合到图像的RGB彩色立方体中的点云,然后查看最小二乘误差如果很小,则这些点位于一条线上,并且您的图像是单色的。我认为该线称为“ 3D正交距离回归(ODR)线”-参见here


作为我自己的参考,我将三胞胎像这样提取到CSV文件中:

#!/usr/local/bin/python3

import numpy as np
from skimage import io

images = ["greyscale","tintype", "sepia", "duotone", "cyanotype"]

for i in images:
   # Load image
   im = io.imread(i + ".jpg")

   # Form list of all RGB triplets
   triplets = im.reshape(-1,3)

   with open(i + ".dat",'w') as f:
      for t in triplets:
         f.write(f"{t[0]} {t[1]} {t[2]}\n")

我像这样用gnuplot进行了3维散点图绘制:

#!/usr/bin/env gnuplot --persist

set xrange [0:255]
set yrange [0:255]
set zrange [0:255]
set ticslevel 0
splot "cyanotype.dat" u 1:2:3 with points

关键词:Python,图像处理,单色,氰基色,底色,双色调,灰度,Gnuplot,散点图,3D,3-d,三胞胎,云。点云,RGB彩色立方体。

© www.soinside.com 2019 - 2024. All rights reserved.