Hello. I have a GUI with an image processing functions. My question is, is it possible to do Back button in this gui? I store and update all events in handles. e.g. handles.inputImage = handles.inputImage_gray, handles.inputImage = handles.inputImage_poisson_noise, handles.inputImage = handles.inputImage_gaussian_filter ... The result is grayscale image with Poisson noise which is filtered by Gaussian Filter... And what if i want to do step back button and remove last event (in this case handles.inputImage = handles.inputImage_gaussian_filter ) and then next and then next last event. Is it possible to store handles in listbox and find last value and then assing to this value inverted state? handles.inputImage_poisson_noise = handles.inputImage. I hope u can understand what i want to do. Thank you very much.

 采纳的回答

Jan
Jan 2018-5-21
编辑:Jan 2018-5-21
After the colors have been converted to gray, there is no way to get the colors back. But of course you can store the initial value (image) in a list to which you append the new image after each operation. Then an undo is easy to implement.
% After loading the image
handles.imageList = {imageRGB};
handles.operation = {'original'};
...
% At applying any operation:
image = rgb2gray(image);
handles.imageList{end+1} = image;
handles.operation{end+1} = {'RGB to gray'};
Now an "undo" is:
if numel(handles.imageList) > 1
image = handles.imageList{end-1};
end
and updating the display, maybe removing the last element from the lists, except you want t "redo".

4 个评论

Note that you must program all of this yourself. None of the gui tools have built-in "undo".
Sir, thank u very much, i understood the syntax, but when i press back button it's working until one state, when i press second press its stopped working. I tried this
//
handles.RGB is input image
// RGB to gray button
handles.RGB_gray = rgb2gray(handles.RGB);
handles.RGB = handles.RGB_gray;
handles.imageList{end+1} = handles.RGB_gray;
imshow(handles.RGB_gray);
guidata(hObject, handles);
// rotate 180 button
handles.RGB_rotate = imrotate(handles.RGB,180);
handles.RGB = handles.RGB_rotate;
handles.imageList{end+1} = handles.RGB_otocenie;
handles.operation{end+1} = {'RGB to gray'};
axes(handles.axes2);
imshow(handles.RGB_rotate);
// Step back button
if numel(handles.imageList) > 1
handles.RGB = handles.imageList{end-1};
imshow( handles.RGB);
guidata(hObject, handles);
end
If you want to undo multiple steps, handles.imageList{end-1} is not sufficient. Add a cursor for the current state:
% For adding a new step:
handles.imageCursor = handles.imageCursor + 1;
handles.imageList{handles.imageCursor} = newImage
handles.operation{handles.imageCursor} = operation
And the undo:
handles.imageCursor = handles.imageCursor - 1;
image = handles.imageList{handles.imageCursor}
Using // for comments is not valid MATLAB code. The Octave forum is elsewhere.

请先登录,再进行评论。

更多回答(1 个)

Thank u, but i did it like this and its working perfectly
if numel(handles.imageList) > 1
handles.imageList(end)=[];
handles.RGB = handles.imageList{end};
handles.imageList
imshow( handles.RGB);
guidata(hObject, handles);
end
Big thank for you :)

Community Treasure Hunt

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

Start Hunting!

Translated by