【问题标题】:Sobel filter is working on the original i/p image but not on the copy of itSobel 过滤器正在处理原始 i/p 图像,但不适用于其副本
【发布时间】:2014-02-16 02:10:22
【问题描述】:

我想在图像上应用 Sobel 和其他过滤器,但只有在原始输入图像上使用过滤器时才能看到过滤器的结果。但是如果我在 inout 图像的副本上实现过滤器,那么什么也不会发生,只会出现一个白色的输出图像。

在下面的代码中,我在原始inputImage 实现过滤器,但我想通过在copyImage 实现它来获得结果。

inputImage=imread('tex.png');
copyImage=double(inputImage);

for i=1:size(C,1)-2
    for j=1:size(C,2)-2
        %Sobel mask for x-direction:
        Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
        %Sobel mask for y-direction:
        Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));

        %The gradient of the image
        inputImage(i,j)=sqrt(Gx.^2+Gy.^2);
    end
end

【问题讨论】:

  • 从copyImage中删除double,然后将for循环中的inputImage替换为copyImage

标签: matlab image-processing computer-vision


【解决方案1】:

imshowdouble 参数期望值在 0.0(黑色)到 1.0(白色)的范围内。任何大于 1 的都被剪裁为白色。由于大概inputImage 是整数,因此使用double(inputImage) 不会重新缩放,并且您最终会得到double 值在0-255 或0-65535 等范围内,具体取决于位深度,因此仅显示为白色。

如果您需要 double 格式,请使用 im2double 正确重新调整值。否则,只需使用copyImage = inputImage 创建一个整数副本。

如果您没有 im2double 的图像处理工具箱,您可以使用以下方法进行无符号整数到双精度图像转换:

dblimg = double(img) ./ double(intmax(class(img)));

【讨论】:

    猜你喜欢
    • 2013-07-22
    • 2021-11-29
    • 2018-10-04
    • 2020-08-05
    • 2019-03-25
    • 2020-09-13
    • 2012-01-02
    • 1970-01-01
    • 2015-07-31
    相关资源
    最近更新 更多