Control image transparency with a slider- appDesigner

조회 수: 8(최근 30일)
João Mendes
João Mendes 2019년 7월 15일
편집: Adam Danz 2021년 2월 10일
Hi all,
I'm trying to control de tranparency of two images using a slider.
Currently, I don't know how to do the code for this feature with a callback function with the slider.
Can anybody help me?
What I wanted, for a better understanding, is that when I'm at a max value, I only see one of the images and at the min value I only see the other. Obviously, when I move the slider I want the transparency of them to change.
Thanks in advance
  댓글 수: 3
Adam 2019년 7월 15일
It would be easier if you post the relevant code you currently have. I don't really have time for long answers from scratch, hence me adding a comment rather than an 'Answer'

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 7월 15일
편집: Adam Danz 2021년 2월 10일
This should get you started.
Two images are plotted on top of each other. A slider is added that sets the AlphaData of the top image.
% Create a figure with two images overlayed
fig = uifigure('HandleVisibility','on');
[X,cmap] = imread('corn.tif');
hold on
[X2,map] = imread('peppers.png');
img2 = imshow(X2,map);
% Create a GUI with a slider that controls the 'AlphaData' value of the currently selected object
sld = uislider(fig,'Position',[50,50,300,3],'Value',1,'Limits',[0,1],...
'ValueChangingFcn', @(sld,event)changeTransparencyFcn(sld,event,img2),...
'BusyAction', 'cancel');
% set the slider properties such as position etc....
% %
function changeTransparencyFcn(~, event, hobj)
% hobj is the image object handle
set(hobj,'AlphaData', event.Value)
drawnow limitrate
Changes made to improve answer on Feb 9, 2021.
  댓글 수: 5
Adam Danz
Adam Danz 2020년 2월 27일
In my answer,
set(gco,'AlphaData', sld.Value)
the slider is controlling the AlphaData property values of the currently selected image.
The link I provided in my previous comment lists properties of images. I don't know what you define as "sensitivity". If you can't figure that out, it might be better to post a new questions since I have limited time right now (feel free to link to this answer).

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by