2016-07-27 33 views
0

我学会了如何做到这一点还不能现在还记得,和我没有通过搜索来获得一些有用的东西。我有一个图像,并希望通过简单地堆叠它们来使用此图像来创建尺寸为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

+0

什么是宪法过滤器? – rayryeng

+0

拼写检查...卷积 – hyiltiz

+0

我想你在谈论'convolve2d'在Python用'边界='与'circular' wrap''或'imfilter'在MATLAB。 – beaker

回答

1

这里是一个完整的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

+0

不错!该计划也很优雅。然而,当我试图将中心图像裁剪1/3和2/3中点时,我可以使用它作为基础来无限生成尺寸为nxn('repmat(base,[nn])')的网格,边缘留下一条细微的痕迹。在算法中是系统的,还是因为裁剪中的一些错误? – hyiltiz

+0

试试这个:centerK = K(1+ size(I,1)-100:(size(I,1)-100)* 2,1 + size(I,2)-100 :(size(I,2 )-100)* 2,:); R = repmat(centerK,[7,7]); figure; imshow(R);' – Rotem

0

你可以尝试以下解决方案:
留下两个连接的图像之间有些重叠区域。
在重叠区域的两幅图像之间进行线性插值。
线性插补: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 

这不是完美的解决方案,而不是一个完整的一个。
很抱歉,但我离开你(或其他SO用户)来完成这项工作。

结果:
enter image description here

+0

结果似乎好多了;我可以从h/2点中剪出缩小的图像。但是,由于我关心的是3x3网格,我想我应该为插值创建更多的网格。然而,如果我们考虑一个角落,一个简单的线性插值似乎会失败。考虑左上角:在3x3网格中,中间图像(2,2)的左上角必须用(1,1),(2,1)和(1,2)这三个图像插值,所以需要一个可以处理2个以上重叠区域的方法。 – hyiltiz