gpt4 book ai didi

matlab - Matlab中使用 slider 旋转图像

转载 作者:行者123 更新时间:2023-12-02 03:03:49 30 4
gpt4 key购买 nike

我在 Matlab 中有一个 GUI(使用 GUIDE),它看起来是这样的:

enter image description here

我想使用 slider 旋转图像并实时显示变化。

我使用轴来显示图像。

我该怎么做?

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

enter image description here

谢谢。

最佳答案

这是一个 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

enter image description here

<小时/>

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

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

  • 使用“属性检查器”,根据需要更改 slider 属性:Min/Max/Value/SliderStep。如果您分配一个标签以便能够在代码中查找组件,也会有所帮助。

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

    handles.I = imread('cameraman.tif');    imshow(I, 'Parent',findobj(hObject,'Tag','imgAxis'))  %# use tag you assigned    guidata(hObject, handles);         %# Update handles structure
  • 为 slider 创建回调事件处理程序,并添加代码:
    angle = round( get(hObject,'Value') );    imshow( imrotate(handles.I,angle) )
<小时/>

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

enter image description here

(插图借自: Understanding Digital Image Interpolation )

关于matlab - Matlab中使用 slider 旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6549538/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com