With few hacks here and there, here it goes -
Main function
function rotationGUI(a)
I = imread(a);
%# c
hFig = figure('menu','none');
hAx = axes('Parent',hFig);
hTxt = uicontrol('Style','text', 'Position',[290 28 20 15], 'String','0');
uicontrol('Parent',hFig, 'Style','slider', 'Value',0, 'Min',0,...
'Max',360, 'SliderStep',[1 10]./360, ...
'Position',[150 5 300 20], 'Callback',{@slider_callback,I,hAx,hTxt,hFig})
uicontrol(hFig,'Style','pushbutton','String','Save and Close',...
'Position',[10 20 120 40],'Callback',{@ok_Callback,I,hTxt,hFig});
%# show image
imshow(I, 'Parent',hAx)
%# Callback function
return;
Associated function -1
function slider_callback(hObj, eventdata,I,hAx,hTxt,hFig)
global Irot
angle = round(get(hObj,'Value')); %# get rotation angle in degrees
Irot = imrotate(I,angle);
imshow(Irot, 'Parent',hAx) %# rotate image
set(hTxt, 'String',num2str(angle)) %# update text
return;
Associated function -2
function ok_Callback(hObj, eventdata,I,hTxt,hFig)
global Irot
set(hTxt, 'String','save')
[filename, pathname] = uiputfile('*.jpg', 'Save Image as');
imwrite(Irot,strcat(pathname,filename));
delete(hFig);
return;
Edit 1: If you would like to save the rotated image as the original image, that is overwrite to it, use these changes -
Edit function rotationGUI
-
uicontrol(hFig,'Style','pushbutton','String','Save and Close',...
'Position',[10 20 120 40],'Callback',{@ok_Callback,I,hTxt,hFig,a});
Edit function ok_callback
-
function ok_callback(hObj, eventdata,I,hTxt,hFig,path1)
global Irot
set(hTxt, 'String','save')
imwrite(Irot,path1);
delete(hFig);
end