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
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.
See also this professional method: https://undocumentedmatlab.com/blog/customizing-uiundo
카테고리
도움말 센터 및 File Exchange에서 Display Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!