Python 如何提取图像中阴影的像素以计算长度?

Python 如何提取图像中阴影的像素以计算长度?,python,computer-vision,feature-extraction,Python,Computer Vision,Feature Extraction,我每分钟都在拍日晷的照片。我想创建一个python程序,根据图像中捕获的阴影长度计算太阳的高度。下面就是这样一幅图。 我试图通过在图像的V通道上使用多大津阈值来获得阴影(在绘制RGB和HSV通道的直方图后,我确定该通道包含的信息最多)。这将导致图像分为以下两类: 我不知道如何进一步处理这张照片,或者我是否应该用不同的方法来处理它以获得阴影。如果这是阴影的最佳提取,我也不知道如何提取阴影的长度。我读过关于斑点的文章,但还没有成功地应用它们。任何关于如何继续/或如何最好地提取阴影的指示都值得赞赏

我每分钟都在拍日晷的照片。我想创建一个python程序,根据图像中捕获的阴影长度计算太阳的高度。下面就是这样一幅图。

我试图通过在图像的V通道上使用多大津阈值来获得阴影(在绘制RGB和HSV通道的直方图后,我确定该通道包含的信息最多)。这将导致图像分为以下两类:

我不知道如何进一步处理这张照片,或者我是否应该用不同的方法来处理它以获得阴影。如果这是阴影的最佳提取,我也不知道如何提取阴影的长度。我读过关于斑点的文章,但还没有成功地应用它们。任何关于如何继续/或如何最好地提取阴影的指示都值得赞赏

下面是一些代码:

%matplotlib inline
import numpy as np
import cv2
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure, show
from skimage import data
from skimage.filters import threshold_multiotsu

def applyMultiOtsu(image, classes):
    # Setting the font size for all plots.
    matplotlib.rcParams['font.size'] = 9

    # Applying multi-Otsu threshold for the default value, generating the classes.
    thresholds = threshold_multiotsu(image, classes)

    # Using the threshold values, we generate the regions.
    regions = np.digitize(image, bins=thresholds)

    # Plotting the original image.
    fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(15, 10))
    ax[0].imshow(image, cmap='gray')
    ax[0].set_title('Original')
    ax[0].axis('off')

    # Plotting the histogram and the two thresholds obtained from multi-Otsu.
    ax[1].hist(image.ravel(), bins=255)
    ax[1].set_title('Histogram')
    for thresh in thresholds:
        ax[1].axvline(thresh, color='r')

    # Plotting the Multi Otsu result.
    ax[2].imshow(regions, cmap='Accent')
    ax[2].set_title('Multi-Otsu result')
    ax[2].axis('off')

    plt.subplots_adjust()
    plt.show()
    return regions

path = "Path to the first image of the post" # Path to the first image of the post
fileName = "20200509131726.png"
img = cv2.imread(path + fileName)
img = img[148:148+444, 249:249+763, :]
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# applyMultiOtsu(hsv[:,:,0]) # Very discrete information, not used currently.
saturation = applyMultiOtsu(hsv[:,:,1], classes=2) # The S channel also proveds useful information
value = applyMultiOtsu(hsv[:,:,2], classes=2) # The V channel contains most information about the image