将鱼眼视频转换为常规视频

时间:2019-03-14 15:05:03

标签: matlab image-processing fisheye

我有一个来自180度鱼眼镜头的视频流。我想进行一些图像处理以将鱼眼视图转换为普通视图。

经过研究和大量阅读文章,我发现this paper

他们描述了解决这个问题的算法(和一些公式)。

我曾经尝试在Matlab中实现此方法。不幸的是,它不起作用,我无法使其起作用。 “校正后”的图像看起来与原始照片完全一样,并且没有任何失真消除,其次,我只是接收到图像的左上角,而不是完整的图像,而是将“ K”的值更改为1.9,从而得到了整个图像的mw ,但图像完全相同。

输入图像:

Input Image

结果:

When the value of K is 1.15 as mentioned in the article

When the value of K is 1.9

这是我的代码:

image = imread('image2.png');
[Cx, Cy, channel] = size(image);

k = 1.5;
f = (Cx * Cy)/3;
opw = fix(f * tan(asin(sin(atan((Cx/2)/f)) * k)));
oph = fix(f * tan(asin(sin(atan((Cy/2)/f)) * k)));
image_new  = zeros(opw, oph,channel);

for i = 1: opw    
    for j = 1: oph        
        [theta,rho] = cart2pol(i,j);        
        R = f * tan(asin(sin(atan(rho/f)) * k));        
        r = f * tan(asin(sin(atan(R/f))/k));        
        X = ceil(r * cos(theta));        
        Y = ceil(r * sin(theta));

        for k = 1: 3            
            image_new(i,j,k) = image(X,Y,k);            
        end
    end
end

image_new = uint8(image_new);
warning('off', 'Images:initSize:adjustingMag');
imshow(image_new);

1 个答案:

答案 0 :(得分:0)

这就是解决我的问题的原因。

输入:     浮点数大于等于0时的强度。0 =无变化,数字越大表示校正越强。     缩放为浮点> =1。(1 =缩放不变)

算法:

set halfWidth = imageWidth / 2
set halfHeight = imageHeight / 2

if strength = 0 then strength = 0.00001
set correctionRadius = squareroot(imageWidth ^ 2 + imageHeight ^ 2) / strength

for each pixel (x,y) in destinationImage
    set newX = x - halfWidth
    set newY = y - halfHeight

    set distance = squareroot(newX ^ 2 + newY ^ 2)
    set r = distance / correctionRadius

    if r = 0 then
        set theta = 1
    else
        set theta = arctangent(r) / r

    set sourceX = halfWidth + theta * newX * zoom
    set sourceY = halfHeight + theta * newY * zoom

    set color of pixel (x, y) to color of source image pixel at (sourceX, sourceY)