How to create an undo button for image colorization?

I'm currently doing an image colorization application in GUI and I'm facing trouble in creating an undo button to undo the colours.
Can anyone help me with this?
Below is my code that might be useful for solving my problem.
Thank you.
function Result = Paint(InputImage,C)
Color(:,:,1)=C(1,1);
Color(:,:,2)=C(1,2);
Color(:,:,3)=C(1,3);
Color=uint8(Color);
Result=InputImage;
Level=graythresh(InputImage);
Img=im2bw(InputImage,Level);
[L,~]=bwlabel(Img);
[X,Y]=ginput(1);
Num=L(ceil(Y),ceil(X));
[R,C]=find(L==Num);
Tmp=[R,C];
for k=1:size(Tmp,1)
Result(Tmp(k,1),Tmp(k,2),1)=Color(:,:,1);
Result(Tmp(k,1),Tmp(k,2),2)=Color(:,:,2);
Result(Tmp(k,1),Tmp(k,2),3)=Color(:,:,3);
end
end

Réponses (1)

Jan
Jan le 3 Mai 2019

0 votes

An "Undo" button does not depend in any way from the applied computations. All you have to do is to store the formerly existing data in the GUI and restore it on demand. Now it matters, how you have created your GUI: With AppDesigner, GUIDE or programmatically? In all cases, create the wanted button and create a backup of the current values e.g. in the ApplicationData or UserData of the figure, before you call the function to modify the data.

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Question posée :

le 3 Mai 2019

Réponse apportée :

Jan
le 3 Mai 2019

Community Treasure Hunt

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

Start Hunting!

Translated by