Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 旋转图像-不同程度_Matlab_Image Processing_Computer Vision - Fatal编程技术网

Matlab 旋转图像-不同程度

Matlab 旋转图像-不同程度,matlab,image-processing,computer-vision,Matlab,Image Processing,Computer Vision,我正在尝试自己的旋转图像算法,而不使用imrotate clear all img1 = imread('image1.jpg');imshow(img1); [m,n,p]=size(img1); thet = pi/6; m1=round(m*1.5); n1=round(n*1.5); rotatedImg = zeros(m1,n1); for i=1:m for j=1:n t = uint16((i)*cos(thet)-(j)*sin(thet)+m+

我正在尝试自己的旋转图像算法,而不使用imrotate

clear all
img1 = imread('image1.jpg');imshow(img1);
[m,n,p]=size(img1);
thet = pi/6;

m1=round(m*1.5);
n1=round(n*1.5);
rotatedImg = zeros(m1,n1);

for i=1:m
    for j=1:n

        t = uint16((i)*cos(thet)-(j)*sin(thet)+m+100);
        s = uint16((i)*sin(thet)+(j)*cos(thet));
        if i>0 && j>0 && i<=m && j<=n

            try rotatedImg(t,s,1)=img1(i,j,1);
            catch
               a=1; 
            end

        end
    end
end


figure;
imshow(rotatedImg);
全部清除
img1=imread('image1.jpg');imshow(img1);
[m,n,p]=尺寸(img1);
t=pi/6;
m1=圆形(m*1.5);
n1=圆形(n*1.5);
rotatedImg=零(m1,n1);
对于i=1:m
对于j=1:n
t=uint16((i)*cos(thet)-(j)*sin(thet)+m+100);
s=uint16((i)*sin(thet)+(j)*cos(thet));

如果i>0&&j>0&&i那么,有两个问题:

  • 始终围绕原点旋转。这就是您需要调整每个角度的偏移(100)的原因。更好的解决方案是围绕图像中心旋转

  • 你没有做任何插值。虽然这本身不是原因,但由于舍入错误,可能会出现目标图像中的每个像素都未命中的情况。最好遍历目标图像并从源图像中获取正确的像素

  • 以下是我的解决方案:

    clear all
    img1 = imread('ngc6543a.jpg');
    imshow(img1);
    [m,n,p]=size(img1);
    thet = pi/6;
    
    m1=round(m*1.5);
    n1=round(n*1.5);
    rotatedImg = zeros(m1,n1, 3, 'uint8');
    tic
    for i=1:m1
        for j=1:n1
    
            p = [i; j] - [m1/2; n1/2];
    
            source = [cos(thet), sin(thet); -sin(thet), cos(thet)] * p;
    
            source = source + [m/2; n/2];       
    
            t = int16(source(1));
            s = int16(source(2));
    
            if t>0 && s>0 && t<=m && s<=n
                rotatedImg(i,j,:) = img1(t,s,:);
            end
        end
    end
    toc
    
    figure;
    imshow(rotatedImg);
    
    全部清除
    img1=imread('ngc6543a.jpg');
    imshow(img1);
    [m,n,p]=尺寸(img1);
    t=pi/6;
    m1=圆形(m*1.5);
    n1=圆形(n*1.5);
    rotatedImg=零(m1,n1,3,'uint8');
    抽搐
    对于i=1:m1
    对于j=1:n1
    p=[i;j]-[m1/2;n1/2];
    source=[cos(thet),sin(thet);-sin(thet),cos(thet)]*p;
    震源=震源+[m/2;n/2];
    t=int16(源(1));
    s=int16(源(2));
    
    如果t>0&&s>0&&tI尝试使用此图像()解决方案,但由于某种原因,图像的顶部和底部被剪裁。我尝试使用这些角度-pi/2,((pi/6)*4)-输出图像被剪裁,并添加适当的边界计算。请注意循环中已更改的索引。非常感谢您的帮助。我想知道你是否可以解释一下,如果上面的不是双线性插值,你使用了什么方法?这可能被称为“最近邻”。使用双线性,您不应该将坐标转换为int16,而是从所有四个相邻像素中获得一些颜色。
    clear all
    img1 = imread('kDdx5.jpg');
    imshow(img1);
    [orgHeight,orgWidth,p]=size(img1);
    thet = pi/7;
    
    matrix = [cos(thet), -sin(thet); sin(thet), cos(thet)];
    p1 = abs(matrix * [orgWidth/2; orgHeight/2]);
    p2 = abs(matrix * [orgWidth/2; -orgHeight/2]);
    
    corner = [max(p1(1), p2(1)); max(p1(2), p2(2))];
    
    newWidth = ceil(2*corner(1));
    newHeight = ceil(2*corner(2));
    rotatedImg = zeros(newHeight, newWidth, 3, 'uint8');
    
    tic
    for i=1:newWidth
        for j=1:newHeight
    
            p = [i; j] - [newWidth/2; newHeight/2];
            source = matrix * p;
            source = source + [orgWidth/2; orgHeight/2;];       
            t = int16(source(1));
            s = int16(source(2));
    
            if t>0 && s>0 && s<=orgHeight && t<=orgWidth
                rotatedImg(j,i,:) = img1(s,t,:);
            end
        end
    end
    toc
    
    figure;
    imshow(rotatedImg);