根据代码,图像显示的结果是一个小白点,这是因为在亚像素边缘检测函数中,没有对亚像素位置进行取整操作。修改代码如下:

function subpixel_image = subpixel_edge_detection(image, moments)
    [rows, cols] = size(image);
    subpixel_image = zeros(rows, cols);
    for x = 1:rows
        for y = 1:cols
            if image(x, y) > 0
                rho = sqrt((2*x-rows-1)^2 + (2*y-cols-1)^2) / sqrt(rows^2 + cols^2);
                theta = atan2((2*y-cols-1), (2*x-rows-1));
                % 使用moments参数计算亚像素边缘位置
                subpixel_x = (rows+1)/2 + rho * cos(theta) + moments(1, 1);
                subpixel_y = (cols+1)/2 + rho * sin(theta) + moments(1, 2);
                % 判断亚像素边缘位置是否在图像范围内
                if subpixel_x >= 1 && subpixel_x <= rows && subpixel_y >= 1 && subpixel_y <= cols
                    subpixel_image(round(subpixel_x), round(subpixel_y)) = 255;
                end
            end
        end
    end
end

在亚像素边缘检测函数中,对subpixel_x和subpixel_y进行取整操作,即使用round()函数对其进行四舍五入取整。这样可以将亚像素位置映射到图像上的整数坐标位置,从而显示出边缘图像。

matlab中此段代码运行后显示图像是一个小白点怎么修改代码? 读取图像image = imreadlenajpg;image = rgb2grayimage; 使用Canny边缘检测算法获取二值化图像bw_image = edgeimage canny; 计算图像的Zernike矩order = 10; Zernike矩的阶数moments = zernike_momentsbw_image

原文地址: https://www.cveoy.top/t/topic/hGkB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录