使用滑块在Matlab中旋转图像 [英] using slider to rotate image in Matlab

查看:170
本文介绍了使用滑块在Matlab中旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Matlab中有一个GUI(使用GUIDE),外观如下:

I have a GUI (using GUIDE) in Matlab, this is how it looks:

我想使用滑块旋转图像并实时显示更改.

I want to rotate the image using slider and to show the change in real time.

我使用轴来显示图像.

我该怎么做?

编辑:我正在构建OCR应用程序.这就是当我旋转盘子时盘子的样子,数字完全变形了.

I'm building OCR application. this is how the plate looks when I'm rotate it, the numbers are totally deformed.

谢谢.

推荐答案

下面是一个示例GUI:

Here is an example GUI:

function rotationGUI()
    %# read image
    I = imread('cameraman.tif');

    %# setup GUI
    hFig = figure('menu','none');
    hAx = axes('Parent',hFig);
    uicontrol('Parent',hFig, 'Style','slider', 'Value',0, 'Min',0,...
        'Max',360, 'SliderStep',[1 10]./360, ...
        'Position',[150 5 300 20], 'Callback',@slider_callback) 
    hTxt = uicontrol('Style','text', 'Position',[290 28 20 15], 'String','0');

    %# show image
    imshow(I, 'Parent',hAx)

    %# Callback function
    function slider_callback(hObj, eventdata)
        angle = round(get(hObj,'Value'));        %# get rotation angle in degrees
        imshow(imrotate(I,angle), 'Parent',hAx)  %# rotate image
        set(hTxt, 'String',num2str(angle))       %# update text
    end
end

如果您希望在GUIDE中构建GUI,请按照以下步骤操作:

If you prefer to build the GUI in GUIDE, follow these steps:

  • 创建GUI,并添加必要的组件:轴,滑块,静态文本(拖放)

  • create GUI, and add necessary components: axis, slider, static text (drag-and-drop)

使用属性检查器",根据需要更改滑块属性:: Min/Max/Value/SliderStep.如果您分配一个Tag以便能够在代码中查找组件,这也将有所帮助.

Using the "Property Inspector", change slider properties as required:: Min/Max/Value/SliderStep. Also would help if you assign a Tag to be able to find components in the code.

在图中的xxxx_OpeningFcn函数中,读取图像并将其存储在handles结构中,然后显示该图像:

In the figure's xxxx_OpeningFcn function, read and store the image in the handles structure, then show it:


    handles.I = imread('cameraman.tif');
    imshow(I, 'Parent',findobj(hObject,'Tag','imgAxis'))  %# use tag you assigned
    guidata(hObject, handles);         %# Update handles structure

  • 为您的滑块创建一个回调事件处理程序,并添加代码:
  • 
        angle = round( get(hObject,'Value') );
        imshow( imrotate(handles.I,angle) )
    


    图像旋转是一种仿射变换,它将输入图像像素的位置(x,y)映射到输出图像的新坐标(x2,y2)上.问题在于输出坐标可能并不总是整数.由于数字图像是在离散像素的网格上表示的,因此采用了某种形式的重采样/插值(这就是为什么当以特定角度旋转时,直线看起来可能呈锯齿状).


    Image rotation is an affine transformation which maps the position (x,y) of input image pixels onto new coordinates (x2,y2) for the output image. The problem is that the output coordinates may not always be integers. Since digital images are represented on a grid of discrete pixels, thus some form of resampling/interpolation is employed (which is why straight lines might look jagged when rotated at certain angles).

    (插图借鉴自:了解数字图像插值)

    这篇关于使用滑块在Matlab中旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆