Rotate image will remove any other image effects in MATLAB

I made a simple image processing project by using MATLAB with GUI, i have a button for uploading an image, another button for making the image black and white and another button to rotate the image. When i press the black and white effect button it works great, but when i press the rotate button the black and white effect will be removed after rotating. How can i fix that ?

 Accepted Answer

Sounds like you are operating on the original image rather than on the gray scale version. How are you getting the image into your callback function for the rotate button? Are you using getimage() to pull it out of the axes? Are you using one of the ways on the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F ????

4 Comments

This is the code i'm using
% --- Executes on button press in loadimage.
function loadimage_Callback(hObject, eventdata, handles)
global im1 im2
path=imgetfile();
im1=imread(path);
im1=im2double(im1);
imshow(im1);
im2=im1;
% --- Executes on button press in b_n_wbtn.
function b_n_wbtn_Callback(hObject, eventdata, handles)
global im1
a=im2bw(im1);
imshow(a);
% --- Executes on button press in rotate90.
function rotate90_Callback(hObject, eventdata, handles)
global im1
f=imrotate(im1,90);
imshow(f);
The (badly-named) "a" is your binary image. You're not doing anything with it in rotate90_Callback() - you're using the original image that was converted to double. You need to make "a" global and use that in rotate90_Callback() instead of im1.
I made it like that
% --- Executes on button press in loadimage.
function loadimage_Callback(hObject, eventdata, handles)
global im1 im2
path=imgetfile();
im1=imread(path);
im1=im2double(im1);
imshow(im1);
im2=im1;
% --- Executes on button press in b_n_wbtn.
function b_n_wbtn_Callback(hObject, eventdata, handles)
global im1 a
a=im2bw(im1);
imshow(a);
% --- Executes on button press in rotate90.
function rotate90_Callback(hObject, eventdata, handles)
global im1 a
f=imrotate(a,90);
imshow(f);
But now it will always rotate the image and make it black and white automatically, what if i want to rotate the original image ?
If you want to rotate the binary image, pass a into imrotate(). If you want to rotate the original image, pass im1 into imrotate.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!