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

回答 (1 件)

Jan
Jan 2019 年 5 月 3 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeDisplay Image についてさらに検索

質問済み:

2019 年 5 月 3 日

回答済み:

Jan
2019 年 5 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by