zoukankan      html  css  js  c++  java
  • 图像变换

    图像平移

    Image = im2double(imread('h.jpg'));
    subplot(1,2,1),imshow(Image),title('原图');
    [h,w,c] = size(Image);
    NewImage = ones(h,w,c);
    deltax = 40;
    deltay = 40;
    for x = 1:w   % 循环扫描新图像中的点
        for y = 1:h
            oldx = x - deltax;   % 确定新图像中的点在原图中的对应点
            oldy = y - deltay;
            if oldx > 0 && oldx < w && oldy > 0 && oldy < h %判断对应是否在图像内
               NewImage(y,x,:) = Image(oldy,oldx,:);
            end;
        end;
    end;
    subplot(1,2,2),imshow(NewImage),title('平移后');
    

    图像翻转

    Image1 = imread('g.jpg');subplot(2,2,1);imshow(Image1);title('原图')
    HImage1 = flipdim(Image1,2);subplot(2,2,2);imshow(HImage1);title('按列翻转')
    HImage2 = flipdim(Image1,1);subplot(2,2,3);imshow(HImage2);title('按行翻转')
    HImage3 = flipdim(HImage1,1);subplot(2,2,4);imshow(HImage3);title('对角翻转')
    

    图像旋转

    Image4 = imread('1.bmp');subplot(1,3,1);imshow(Image4);title('原图');
    NewImage4 = imrotate(Image4,45,"bilinear");
    NewImage5 = imrotate(Image4,45);
    subplot(1,3,2);imshow(NewImage4);title('双线性插值');
    subplot(1,3,3);imshow(NewImage5);title('最邻近插值');
    

    图像放大缩小错切 

    clear;
    Image = im2double(imread('h.jpg'));
    tform1 = maketform('affine',[1 0 0;0.5 1 0;0 0 1]);
    tform2=  maketform('affine',[1 0.5 0;0 1 0;0 0 1]);
    
    NewImage = imresize(Image,2,'nearest');
    NewImage1 = imresize(Image,0.5,'nearest');
    NewImage2 = imtransform(Image,tform1);
    NewImage3 = imtransform(Image,tform2);
    
    subplot(2,3,1);imshow(Image);title('原图');
    subplot(2,3,2);imshow(NewImage);title('放大2倍');
    subplot(2,3,3);imshow(NewImage1);title('缩小0.5倍');
    subplot(2,3,4);imshow(NewImage2);title('水平方向错切');
    subplot(2,3,5);imshow(NewImage3);title('垂直平方向错切');
    

    汇总

    matlab GUI 窗口交互显示

    创建GUI

    命令行中输入:guide

    放控件

    编写触发函数

    选中button ,右键

     

    function pushbutton1_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    axes(handles.axes1)  % axes1是控件“坐标区1”的tig
    [fn,pn,~] = uigetfile('*.jpg','请选择要识别的图片');
    global I;  %设置为全局变量,才能在不同控件函数中调用
    I = imread([pn fn]);
    imshow(I);
    title('原图像');
    
    function pushbutton2_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton2 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    axes(handles.axes2);
    global I;  %使用全局变量时,也要声明一下
    HI = flipdim(I,2);
    imshow(HI);
    title('水平翻转');
    
    function pushbutton3_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton3 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    axes(handles.axes3);
    global I;  %使用全局变量时,也要声明一下
    tform1 = maketform('affine',[1 0 0;0.5 1 0;0 0 1]);
    NewImage2 = imtransform(I,tform1);
    imshow(NewImage2);
    

    运行效果:

     

    作者: Pam

    出处: https://www.cnblogs.com/pam-sh/>

    关于作者:网安在读

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 原文链接 如有问题, 可邮件(mir_soh@163.com)咨询.

  • 相关阅读:
    redis
    装饰器之functools与before_request
    版本
    git常用命令
    支付宝支付示例
    ContentType
    vue的基础使用
    es6简单介绍
    解析器、路由控制、分页与响应器
    元素水平居中的方法
  • 原文地址:https://www.cnblogs.com/pam-sh/p/13863602.html
Copyright © 2011-2022 走看看