平滑过滤图像边界以创建圆形图像(傅里叶准备)

2024-06-02 14:33:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我学会了怎么做,但现在记不起来了,也没能通过搜索找到有用的东西。我有一个图像,想用这个图像创建一个更大的图像大小3x3简单地堆叠他们。边界必须平滑,以便图像的右边缘无缝地转换为图像的左边缘。在

enter image description here

应用卷积滤波器应该可以做到,因为它认为图像是圆形的,但我们到底应该怎么做呢?我们可以说Matlab(或任何其他你能说/打字的语言)。在

编辑1: 我更喜欢只对边界应用过滤器,同时尽可能保留原始图像。在

编辑2: 我试过高斯滤波器。虽然它模糊了整个图像,但边缘变得比模糊的中间更突出。 imshow(repmat(imfilter(imread('un1vY.jpg'), fspecial('gaussian',64,8), 'circular'), [3 3]))

enter image description here


Tags: 图像语言编辑过滤器圆形无缝卷积边缘
2条回答

这是一个完整的3x3样品:

function Test()
    close all
    I = imread('un1vY.jpg');
    I = double(I)/255;      %Convert uint8 to double    

    J = HorizFuse(I);

    Jtag = cat(3, J(:,:,1)', J(:,:,2)', J(:,:,3)'); %Transpose across 2'nd dimension.

    K = HorizFuse(Jtag);

    K = cat(3, K(:,:,1)', K(:,:,2)', K(:,:,3)');  %Transpose back

    K = uint8(K*255); %Convert back to uint8
    figure;imshow(K);

    imwrite(K, 'K.jpg');    
end


function K = HorizFuse(I)
    h = linspace(0,1,100);  %Create ramp from 0 to 1 of 100 elements.

    im_w = size(I, 2); %Image width
    im_h = size(I, 1); %Image height

    Hy = repmat(h, [size(I, 1), 1, 3]); %Replicate h to fit image height.

    J = zeros(im_h, im_w*2-100, 3);
    J(:, 1:im_w-100, :) = I(:, 1:im_w-100, :); %Fill pixels from the left to overlap.
    J(:, im_w+1:end, :) = I(:, 101:end, :);    %Fill pixels from the right of overlap.

    %Fill overlap with linear intepolation between right side of left image and left side of right image.
    J(:, im_w-99:im_w, :) = I(:, end-99:end, :).*(1-Hy) + I(:, 1:100, :).*Hy;

    K = zeros(im_h, im_w*3-100*2, 3);
    K(1:size(J,1), 1:size(J,2), :) = J;
    K(1:size(J,1), end-(im_w+100)+1:end, :) = J(1:size(J,1), end-(im_w+100)+1:end, :);
end

结果:
enter image description here

您可以尝试以下解决方案:
在两个附加图像之间留一些重叠区域。
在重叠区域的两个图像之间进行线性插值。
线性插值:h*A+(1-h)*B当h从0到1时。在

水平附加图像的h(复制以创建图像)插图:
enter image description here

我拍摄了100像素宽的重叠。
以下代码水平附加两个图像:

I = imread('un1vY.jpg');
I = double(I)/255;      %Convert uint8 to double
h = linspace(0,1,100);  %Create ramp from 0 to 1 of 100 elements.

im_w = size(I, 2); %Image width
im_h = size(I, 1); %Image height

Hy = repmat(h, [size(I, 1), 1, 3]); %Replicate h to fit image height.

J = zeros(im_h, im_w*2-100, 3);
J(:, 1:im_w-100, :) = I(:, 1:im_w-100, :); %Fill pixels from the left to overlap.
J(:, im_w+1:end, :) = I(:, 101:end, :);    %Fill pixels from the right of overlap.

%Fill overlap with linear intepolation between right side of left image and left side of right image.
J(:, im_w-99:im_w, :) = I(:, end-99:end, :).*(1-Hy) + I(:, 1:100, :).*Hy;

J = uint8(J*255); %Convert back to uint8

这不是完美的解决方案,也不是一个完整的解决方案。
对不起,我让你(或其他用户)来完成这项工作。在

结果:
enter image description here

相关问题 更多 >