Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 如何确定图像是否为单色_Image_Colors_Scale - Fatal编程技术网

Image 如何确定图像是否为单色

Image 如何确定图像是否为单色,image,colors,scale,Image,Colors,Scale,我必须确定图像是否是单色的。我的意思是单色不仅仅是黑白。。它可能是深褐色,像红色或蓝色阴影,甚至混合红色和蓝色阴影a.s.o(单色比例) 我想我们可以说刻度从黑色(0,0,0)到白色(255255),但它不是线性的。。它是每个颜色通道上的特定曲线 我希望我说得很清楚:)如果你想到这样的灰度图像: 图像中出现的所有RGB三元组将位于或接近RGB[0,0,0]即黑色到RGB[255255]即RGB颜色立方体中白色的直线上: 这就是所有单色图像的情况——所有RGB三元组都会出现在RGB彩色立方体中

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

我想我们可以说刻度从黑色(0,0,0)到白色(255255),但它不是线性的。。它是每个颜色通道上的特定曲线


我希望我说得很清楚:)

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

图像中出现的所有RGB三元组将位于或接近RGB[0,0,0]即黑色到RGB[255255]即RGB颜色立方体中白色的直线上:

这就是所有单色图像的情况——所有RGB三元组都会出现在RGB彩色立方体中的一条直线附近。在蓝字印刷中,直线将穿过深蓝色和浅蓝色。在深褐色图像中,直线将穿过棕色和浅棕色,在红-蓝双色图像中,直线将连接RGB立方体中的红点和蓝点

让我们看看一些图像和它们的散点图

灰度


cyanotype


duotone


乌贼墨


我认为一种可能适用于你的技术是在你的图像的RGB颜色立方体中,在点云上拟合一条直线,然后看看最小二乘误差,如果误差很小,点位于一条线上,你的图像是单色的。我认为这条线被称为“三维正交距离回归(ODR)线”——参见

我现在已经试过数学了。基本上,我相信我可以计算出三元组的奇异值分解,得到三个主成分中的方差。如果所有RGB三联体位于一条直线上,那么所有方差将沿着该直线,在第一主成分中,它将是100%,第二和第三主成分将是零。如果RGB三元组大部分位于第一个分量中,第二个分量的百分比较小,第三个分量的百分比则为零,这意味着它们大部分位于一条直线上,并且只倾向于偏离该直线的一个垂直方向,因此点云将看起来像一个长而平的椭圆。如果第二个和第三个分量相当大,则点云为三维雪茄形状。如果第一个分量不包含非常显著的方差百分比,则RGB三联体不会落在一条直线上

#!/usr/local/bin/python3

import sys
import numpy as np
from skimage import io
from skimage.transform import resize

if len(sys.argv) != 2:
   sys.exit("Usage: mono.py filename")

path = sys.argv[1]
im = io.imread(path)

# Down-res image to make SVD time reasonable
im = resize(im,(128,128))

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

# Get mean on all axes
means = triplets.mean(axis=0)

# Calculate SVD
uu, dd, vv = np.linalg.svd(triplets - means)

# dd holds the variance in each of the PCA directions
# The key factor is what percentage of the variance is held in the first direction
PC1var = dd[0]*100./dd.sum()
PC2var = dd[1]*100./dd.sum()
PC3var = dd[2]*100./dd.sum()
print(f"PC1 variance: {PC1var}")
print(f"PC2 variance: {PC2var}")
print(f"PC3 variance: {PC3var}")
对我的测试图像运行上面的代码会得到90%以上的结果,对于正常的非单色照片,会得到60%左右的值。请在投入生产之前做一些测试


作为我自己的参考,我将三元组提取到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")
#!/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
我用gnuplot做了三维散点图,如下所示:

#!/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")
#!/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、splot、3D、3D、三胞胎、云。点云,RGB彩色立方体

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

图像中出现的所有RGB三元组将位于或接近RGB[0,0,0]即黑色到RGB[255255]即RGB颜色立方体中白色的直线上:

这就是所有单色图像的情况——所有RGB三元组都会出现在RGB彩色立方体中的一条直线附近。在蓝字印刷中,直线将穿过深蓝色和浅蓝色。在深褐色图像中,直线将穿过棕色和浅棕色,在红-蓝双色图像中,直线将连接RGB立方体中的红点和蓝点

让我们看看一些图像和它们的散点图

灰度


cyanotype


duotone


乌贼墨


我认为一种可能适用于你的技术是在你的图像的RGB颜色立方体中,在点云上拟合一条直线,然后看看最小二乘误差,如果误差很小,点位于一条线上,你的图像是单色的。我认为这条线被称为“三维正交距离回归(ODR)线”——参见

我现在已经试过数学了。基本上,我相信我可以计算出三元组的奇异值分解,得到三个主成分中的方差。如果所有RGB三联体位于一条直线上,那么所有方差将沿着该直线,在第一主成分中,它将是100%,第二和第三主成分将是零。如果RGB三元组大部分位于第一个分量中,第二个分量的百分比较小,第三个分量的百分比则为零,这意味着它们大部分位于一条直线上,并且只倾向于偏离该直线的一个垂直方向,因此点云将看起来像一个长而平的椭圆。如果第二个和第三个分量相当大,则点云为三维雪茄形状。如果第一个分量不包含非常显著的方差百分比,则RGB三联体不会落在一条直线上

#!/usr/local/bin/python3

import sys
import numpy as np
from skimage import io
from skimage.transform import resize

if len(sys.argv) != 2:
   sys.exit("Usage: mono.py filename")

path = sys.argv[1]
im = io.imread(path)

# Down-res image to make SVD time reasonable
im = resize(im,(128,128))

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

# Get mean on all axes
means = triplets.mean(axis=0)

# Calculate SVD
uu, dd, vv = np.linalg.svd(triplets - means)

# dd holds the variance in each of the PCA directions
# The key factor is what percentage of the variance is held in the first direction
PC1var = dd[0]*100./dd.sum()
PC2var = dd[1]*100./dd.sum()
PC3var = dd[2]*100./dd.sum()
print(f"PC1 variance: {PC1var}")
print(f"PC2 variance: {PC2var}")
print(f"PC3 variance: {PC3var}")
对我的测试图像运行上面的代码会得到90%以上的结果,对于正常的非单色照片,会得到60%左右的值。请在投入生产之前做一些测试


作为我自己的参考,我将三元组提取到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")
#!/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
我用gnuplot做了三维散点图,如下所示:

#!/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")
#!/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、splot、3D、3D、三胞胎、云。点云,RGB彩色立方体

我加入了一些数学计算来计算像素偏离直线的距离。请再看一看。我已经加入了一些数学来计算像素与直线l的偏差有多远