如何找到圆形的上下边界以检测虹膜和瞳孔?

问题描述

当我尝试为瞳孔找到2个圆圈的内部圆圈而为虹膜找到一个外部的圆圈但无法这样做时,我得到了一个错误。首先,我对图像进行整形,然后找到带宽以了解内核值,然后使用均值偏移算法进行分割,然后将群集区域标记为红色:

    import tkinter as tk
    from tkinter import filedialog
    from PIL import ImageTk,Image
    import numpy as np
    import scipy.ndimage as snd
    from sklearn.cluster import MeanShift,estimate_bandwidth
    from sklearn.datasets.samples_generator import make_blobs
    from itertools import cycle
    from PIL import Image
    import matplotlib.pyplot as plt
    import matplotlib.pylab as pylab
    import cv2
    pylab.rcParams['figure.figsize'] = 16,12


    root = tk.Tk()
    root.withdraw()

    file_path = filedialog.askopenfilename(initialdir="F:\mean shift\images",title="Open File",filetypes= (("all files","*.*"),("jpg files","*.jpg")))
   
    image = Image.open(file_path)


    image = np.array(image)
    original_shape = image.shape

    # Flatten image.
    X = np.reshape(image,[-1,3])

    plt.imshow(image)

    bandwidth = estimate_bandwidth(X,quantile=0.1,n_samples=100)
    print(bandwidth)

    ms = MeanShift(bandwidth=bandwidth,bin_seeding=True)
    ms.fit(X)

    labels = ms.labels_
    print(labels.shape)
    cluster_centers = ms.cluster_centers_
    print(cluster_centers.shape)

    labels_unique = np.unique(labels)
    n_clusters_ = len(labels_unique)

    print("number of estimated clusters : %d" % n_clusters_)

   segmented_image = np.reshape(labels,original_shape[:2])  # Just take size,ignore RGB channels.
   plt.figure(2)
   plt.imshow(segmented_image)
   plt.axis('off')
   masked_image = np.copy(image)
   # convert to the shape of a vector of pixel values
   masked_image = masked_image.reshape((-1,3))
   # color (i.e cluster) to disable
   cluster = 2
   masked_image[labels == cluster] = [255,0]

   # convert back to original shape
   masked_image = masked_image.reshape(image.shape)
   # show the image
   plt.imshow(masked_image)
   nemo = cv2.cvtColor(masked_image,cv2.COLOR_BGR2RGB)
   cv2.imwrite("mean_shift.bmp",nemo)
   plt.show()

Original

output

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...