zoukankan      html  css  js  c++  java
  • matlab练习程序(图像水平/竖直移动)

    cl;
    delta_x=67; %要求为整数,水平移动的偏移量,正为向右,负为向左
    delta_y=-89; %要求为整数,竖直移动的偏移量,正为向下,负为向上
    img=imread('Corner.png'); %这里v为原图像的高度,u为原图像的宽度
    imshow(img); %这里y为变换后图像的高度,x为变换后图像的宽度
    [v u]=size(img);

    imgn=zeros(v+abs(delta_y),u+abs(delta_x));
    rot=[1 0 0;0 1 0;delta_y delta_x 1];
    inv_rot=inv(rot);
    pix1=[1 1 1]*rot; %pix1(1),pix1(2)分别为变换后图像的左上角的y,x
    pix4=[v u 1]*rot; %pix4(1),pix4(2)分别为变换后图像的右下角的y,x

    %%向右下方移动
    if delta_x>=0 && delta_y>=0
    for y=pix1(1):pix4(1)
    for x=pix1(2):pix4(2)
    pix=[y x 1]*inv_rot;
    if pix(1)>=0.5 && pix(2)>=0.5 && pix(1)<=v && pix(2)<=u
    imgn(y,x)=img(round(pix(1)),round(pix(2)));
    end
    end
    end
    end

    %%向左下方移动
    if delta_x<0 && delta_y>=0
    for y=pix1(1):pix4(1)
    for x=pix1(2):pix4(2)
    pix=[y x 1]*inv_rot;
    if pix(1)>=0.5 && pix(2)>=0.5 && pix(1)<=v && pix(2)<=u
    imgn(y,x-delta_x)=img(round(pix(1)),round(pix(2)));
    end
    end
    end
    end

    %%向左上方移动
    if delta_x<0 && delta_y<0
    for y=pix1(1):pix4(1)
    for x=pix1(2):pix4(2)
    pix=[y x 1]*inv_rot;
    if pix(1)>=0.5 && pix(2)>=0.5 && pix(1)<=v && pix(2)<=u
    imgn(y-delta_y,x-delta_x)=img(round(pix(1)),round(pix(2)));
    end
    end
    end
    end

    %%向右上方移动
    if delta_x>=0 && delta_y<0
    for y=pix1(1):pix4(1)
    for x=pix1(2):pix4(2)
    pix=[y x 1]*inv_rot;
    if pix(1)>=0.5 && pix(2)>=0.5 && pix(1)<=v && pix(2)<=u
    imgn(y-delta_y,x)=img(round(pix(1)),round(pix(2)));
    end
    end
    end
    end

    figure,imshow(uint8(imgn))
  • 相关阅读:
    vue create is a Vue CLI 3 only command and you are using Vue CLI 2.9.6. You
    Vue2.x是怎么收集依赖的
    只绑定一次事件的简单方法
    Proxy是怎么做数据劫持的
    使用babel进行打包
    使用npm link进行模块调试
    Webpack 热加载插件的实现原理
    Vue 服务端渲染的数据流
    Vue的生命周期钩子
    Linux定时任务
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2385159.html
Copyright © 2011-2022 走看看