Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.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
Python 无法获得带有亮点的图像的准确阈值_Python_Opencv_Image Processing - Fatal编程技术网

Python 无法获得带有亮点的图像的准确阈值

Python 无法获得带有亮点的图像的准确阈值,python,opencv,image-processing,Python,Opencv,Image Processing,我试图在图像中发现一个巨大的亮斑。我这样做的方式是,首先将其转换为COLOR\u BGR2HLS\u FULL,采用绿色通道并对其应用高斯模糊,然后使用THRESH\u OTSU获得阈值图像,然后绘制轮廓: self.result = cv2.cvtColor(self.result_array_color, cv2.COLOR_BGR2HLS_FULL) self.result = self.result[:,:,1] self.result = cv2.GaussianBlur(self.

我试图在图像中发现一个巨大的亮斑。我这样做的方式是,首先将其转换为
COLOR\u BGR2HLS\u FULL
,采用绿色通道并对其应用高斯模糊,然后使用
THRESH\u OTSU
获得阈值图像,然后绘制轮廓:

self.result = cv2.cvtColor(self.result_array_color, cv2.COLOR_BGR2HLS_FULL)
self.result = self.result[:,:,1] 
self.result = cv2.GaussianBlur(self.result,(25,25), 0)
以下是获得的图像的外观:

下面是所需图像的外观:

而且,我的方式与所有类似类型的图像不一致。你有没有更好的建议


谢谢大家!

嗯,我得到了这个结果:

初始图像(我没有原始图像,因此删除了您的绿线):

使用绿色通道进行处理:

然后使用带有半径为32的方形窗口的膨胀和腐蚀过滤器移除容器:

扩张后

侵蚀后

照明抑制滤波器(或高通滤波器-图像高斯平滑分割)使图像更清晰:

最后是一个门槛

还可以平滑最终遮罩

并再次使用阈值以获得更平滑的结果:


好吧,我得到了这个结果:

初始图像(我没有原始图像,因此删除了您的绿线):

使用绿色通道进行处理:

然后使用带有半径为32的方形窗口的膨胀和腐蚀过滤器移除容器:

扩张后

侵蚀后

照明抑制滤波器(或高通滤波器-图像高斯平滑分割)使图像更清晰:

最后是一个门槛

还可以平滑最终遮罩

并再次使用阈值以获得更平滑的结果:


不,我没有使用任何其他修复技术来移除容器。 膨胀是某个区域内的最大值,侵蚀是最小值。我使用了扩张和侵蚀半径32和高通半径128

代码用C#表示:

公共字节[]扩展(字节[]图像,整数宽度,整数高度,整数半径)
{
byte[]temp=新字节[image.Length];
字节[]结果=新字节[image.Length];
//放大X
对于(int y=0;y
不,我没有使用任何其他修复技术来移除容器。 膨胀是某个区域内的最大值,侵蚀是最小值。我使用了扩张和侵蚀半径32和高通半径128

代码用C#表示:

公共字节[]扩展(字节[]图像,整数宽度,整数高度,整数半径)
{
byte[]temp=新字节[image.Length];
字节[]结果=新字节[image.Length];
//放大X
对于(int y=0;y    public byte[] Dilate(byte[] image, int width, int height, int radius)
{
    byte[] temp = new byte[image.Length];
    byte[] result = new byte[image.Length];

    //Dilate by X
    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
        {
            byte v = 0;
            for (int i = x - radius; i <= x + radius; i++)
                if (i >= 0 && i < width)
                    v = Math.Max(v, image[i + y * width]);
            temp[x + y * width] = v;
        }

    //Dilate by Y
    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
        {
            byte v = 0;
            for (int i = y - radius; i <= y + radius; y++)
                if (i >= 0 && i < height)
                    v = Math.Max(v, temp[x + i * width]);
            result[x + y * width] = v;
        }

    return result;
}

public byte[] Erode(byte[] image, int width, int height, int radius)
{
    byte[] temp = new byte[image.Length];
    byte[] result = new byte[image.Length];

    //Dilate by X
    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
        {
            byte v = 255;
            for (int i = x - radius; i <= x + radius; i++)
                if (i >= 0 && i < width)
                    v = Math.Min(v, image[i + y * width]);
            temp[x + y * width] = v;
        }

    //Dilate by Y
    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
        {
            byte v = 255;
            for (int i = y - radius; i <= y + radius; y++)
                if (i >= 0 && i < height)
                    v = Math.Min(v, temp[x + i * width]);
            result[x + y * width] = v;
        }

    return result;
}

public byte[] HighPass(byte[] image, int width, int height, float radius)
{
    byte[] smooth = GaussSmooth(image, width, height, (byte)radius);
    byte[] result = new byte[image.Length];

    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
        {
            result[x + y * width] = (byte)(128 + image[x + y * width] - smooth[x + y * width]);
        }

    return result;
}