using slider to rotate image in Matlab -
i have gui (using guide) in matlab, how looks:
i want rotate image using slider , show change in real time.
i use axes display image.
how can this?
edit: i'm building ocr application. how plate looks when i'm rotate it, numbers totally deformed.
thanks.
here example gui:
function rotationgui() %# read image = 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')); %# rotation angle in degrees imshow(imrotate(i,angle), 'parent',hax) %# rotate image set(htxt, 'string',num2str(angle)) %# update text end end
if prefer build gui in guide, follow these steps:
create gui, , add necessary components: axis, slider, static text (drag-and-drop)
using "property inspector", change slider properties required::
min/max/value/sliderstep
. if assigntag
able find components in code.in figure's
xxxx_openingfcn
function, read , store image inhandles
structure, show it:
handles.i = imread('cameraman.tif'); imshow(i, 'parent',findobj(hobject,'tag','imgaxis')) %# use tag assigned guidata(hobject, handles); %# update handles structure
- create callback event handler slider, , add code:
angle = round( get(hobject,'value') ); imshow( imrotate(handles.i,angle) )
edit: image rotation affine transformation maps position (x,y) of input image pixels onto new coordinates (x2,y2) output image. problem output coordinates may not integers. since digital images represented on grid of discrete pixels, form of resampling/interpolation employed (which why straight lines might jagged when rotated @ angles).
(illustration borrowed from: understanding digital image interpolation)
Comments
Post a Comment